标签:
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
#include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> using namespace std; #define ll __int64 #define esp 0.00000000001 const int N=1e5+10,M=1e7+10,inf=1e9+10; const ll mod=998244353; ll a[N]; struct is { ll x,y; }gg[N]; int cmp(is x,is y) { if(x.y!=y.y) return x.y<y.y; return x.x<y.x; } ll check(ll x,ll y,ll l,ll r) { ll maxx=max(x,l); ll minn=min(r,y); if(maxx<=minn) return minn-maxx+1; return 0; } is he(ll x,ll y,ll l,ll r) { is ans; ans.x=min(x,l); ans.y=max(r,y); return ans; } int main() { ll x,y,z,i,t; int T; ll L,R; scanf("%d",&T); while(T--) { scanf("%I64d%I64d%I64d",&x,&L,&R); for(i=1;i<=x;i++) scanf("%I64d",&a[i]); sort(a+1,a+x+1); for(i=1;i<x;i++) { gg[i].x=a[i+1]-a[i]+1; gg[i].y=a[i+1]+a[i]-1; } sort(gg+1,gg+x,cmp); int ji=0; gg[ji].x=gg[1].x; gg[ji].y=gg[1].y; ji++; for(i=2;i<x;i++) { if(gg[i].x<=gg[ji-1].y) { gg[ji-1]=he(gg[i].x,gg[i].y,gg[ji-1].x,gg[ji-1].y); } else { gg[ji].x=gg[i].x; gg[ji].y=gg[i].y; ji++; } } ll ans=0; for(i=0;i<ji;i++) { ans+=check(gg[i].x,gg[i].y,L,R); } printf("%I64d\n",R-L+1-ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5679649.html