QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198858 | #5144. Set of Intervals | 275307894a | WA | 5ms | 6084kb | C++14 | 1.8kb | 2023-10-03 17:56:50 | 2023-10-03 17:56:50 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=N*60+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=2e9+7;mt19937 rnd(263082);
int n,A[N],B[N],Ns[N],Nh,g[N],w[N];
void del(int Is){
int i;
for(i=1;i<=n;i++) if(A[i]>Is) A[i]--,B[i]--;
for(i=Is;i<=Nh;i++) swap(w[i],w[i+1]);Nh--;
fill(g+1,g+Nh+1,0);
for(i=1;i<=n;i++) g[A[i]]++,g[B[i]+1]--;
for(i=1;i<=Nh;i++) g[i]+=g[i-1];
}
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);if(n==1){puts("1");return;}
Nh=0;for(i=1;i<=n;i++) Ns[++Nh]=A[i],Ns[++Nh]=B[i]+1;
sort(Ns+1,Ns+Nh+1);Nh=unique(Ns+1,Ns+Nh+1)-Ns-1;
for(i=1;i<=n;i++) A[i]=LB(Ns+1,Ns+Nh+1,A[i])-Ns,B[i]=LB(Ns+1,Ns+Nh+1,B[i]+1)-Ns-1;
fill(g+1,g+Nh+1,0);for(i=1;i<=n;i++) g[A[i]]++,g[B[i]+1]--;
for(i=1;i<=Nh;i++) g[i]+=g[i-1];Nh--;for(i=1;i<=Nh;i++) w[i]=Ns[i+1]-Ns[i];
int Is=0;for(i=1;i<=Nh;i++) if(!g[i]) {Is=i;break;}
if(Is){
int Ct=0;for(i=1;i<=n;i++) if(B[i]<Is) Ct++;
if(Ct==1) del(Is);
}
Is=0;for(i=Nh;i;i--) if(!g[i]) {Is=i;break;}
if(Is){
int Ct=0;for(i=1;i<=n;i++) if(A[i]>Is) Ct++;
if(Ct==1) del(Is);
}
ll ans=0;for(i=1;i<=Nh;i++) ans+=w[i];
ans=ans*(ans-1)/2;
if(g[1]==1) ans-=1ll*w[1]*(w[1]-1)/2;
if(g[Nh]==1) ans-=1ll*w[Nh]*(w[Nh]-1)/2;
printf("%lld\n",ans);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6084kb
input:
4 1 1 1000000000 2 1 1000000000 1 1000000000 4 1 2 3 4 5 6 7 8 4 1 3 2 4 5 8 6 7
output:
1 499999999500000000 26 28
result:
ok 4 number(s): "1 499999999500000000 26 28"
Test #2:
score: 0
Accepted
time: 2ms
memory: 6012kb
input:
10000 1 778216842 910688403 1 513404058 890988011 1 1 1000000000 1 1 1000000000 1 758932694 848837772 1 516433381 715411928 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 1 1000000000 1 652548522 898071173 1 1 1000000000 1 509357508 603420032 1 1 1000000000 1 657294869 887475066 1 1 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 10000 numbers
Test #3:
score: -100
Wrong Answer
time: 5ms
memory: 6024kb
input:
10000 2 427286995 863604876 582970459 874563920 2 181948005 565025282 799528580 848659925 2 1 1000000000 716032287 836380611 2 383809946 544540272 520881396 990456979 2 156308569 178412791 731100211 963724967 2 426113388 802990296 556666621 560014605 2 1 1000000000 575838571 811122140 2 255734272 64...
output:
87849603321470913 18821102290156188 230263230414266279 75195165925255965 5141989504048811 32977435735183263 316367547533445965 56483863859672889 37024984393194673 36132096841419954 57797703310407226 307857554310722843 261703336965133219 3932968549941246 63833225117266922 49459548807361176 7005773885...
result:
wrong answer 3rd numbers differ - expected: '113106465274673025', found: '230263230414266279'