QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#198866 | #5144. Set of Intervals | 275307894a | WA | 5ms | 6092kb | C++14 | 1.9kb | 2023-10-03 18:02:51 | 2023-10-03 18:02:51 |
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;
if(g[1]==1&&g[Nh]==1){
int flag=0;for(i=1;i<=n;i++) if(A[i]==1&&B[i]==Nh) flag=1;
if(flag) ans-=1ll*w[1]*w[Nh];
}
printf("%lld\n",ans);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6028kb
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: 6028kb
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: 0
Accepted
time: 5ms
memory: 4064kb
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 113106465274673025 75195165925255965 5141989504048811 1256173734724260 207604390726385765 56483863859672889 37024984393194673 36132096841419954 22573394495301601 143688903920213372 166852999281224709 3932968549941246 63833225117266922 49459548807361176 70057738855...
result:
ok 10000 numbers
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 6092kb
input:
10000 3 1 1000000000 521067549 666980062 562319713 714009993 3 42407212 75107815 610219669 973789020 873806856 902158965 3 1 1000000000 673648508 809445815 599994567 757240668 3 92939611 410549965 597447135 678622426 676819188 811525072 3 230740729 455081734 606008912 926990742 615223886 822068791 3...
output:
174329051362239765 75414841727517399 187516336041444375 82076494957525608 118019746781465126 303666532800970347 176358932288144970 330593156050995465 38304933271691114 247444999637419584 11261001704542560 199454344726240709 125887172098178353 106103534848241880 200274422590053105 105365559326127666 ...
result:
wrong answer 2nd numbers differ - expected: '269965111370246655', found: '75414841727517399'