标签:
题目链接:
Time Limit: 8000/4000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++) #define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) { char CH; bool F=false; for(CH=getchar();CH<‘0‘||CH>‘9‘;F= CH==‘-‘,CH=getchar()); for(num=0;CH>=‘0‘&&CH<=‘9‘;num=num*10+CH-‘0‘,CH=getchar()); F && (num=-num); } int stk[70], tp; template<class T> inline void print(T p) { if(!p) { puts("0"); return; } while(p) stk[++ tp] = p%10, p/=10; while(tp) putchar(stk[tp--] + ‘0‘); putchar(‘\n‘); } const LL mod=998244353; const double PI=acos(-1.0); const int inf=1e9; const int N=1e5+10; const int maxn=1e3+10; const double eps=1e-6; int n; LL l,r,a[N]; struct node { LL l,r; }po[N]; int cmp(node x,node y) { if(x.l==y.l)return x.r<y.r; return x.l<y.l; } int vis[N]; int main() { int t; read(t); while(t--) { mst(vis,0); read(n);read(l);read(r); For(i,0,n-1)read(a[i]); sort(a,a+n); For(i,1,n-1) { po[i].r=a[i]+a[i-1]-1; po[i].l=a[i]-a[i-1]+1; } sort(po+1,po+n,cmp); LL len=0; For(i,1,n-1) { if(i==n-1)continue; if(po[i].r<po[i+1].l)continue; else { po[i+1].l=po[i].l; po[i+1].r=max(po[i].r,po[i+1].r); vis[i]=1; } } For(i,1,n) { if(!vis[i]) { if(po[i].l>r||po[i].r<l||po[i].l>po[i].r)continue; LL L=max(po[i].l,l),R=min(po[i].r,r); len=len+(R-L+1); } } cout<<r-l+1-len<<"\n"; } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangchengc919/p/5680181.html