QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630236 | #5144. Set of Intervals | 999# | WA | 5ms | 7940kb | C++14 | 1.5kb | 2024-10-11 17:16:35 | 2024-10-11 17:16:36 |
Judging History
answer
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
const int N=200007;
int n,e,ml,sr,L[N],R[N],E[N],D[N],W[N],F[N];
void magic() {
scanf("%d",&n);
e=sr=0;
For(i,1,n) {
scanf("%d%d",&L[i],&R[i]);
E[++e]=R[i],E[++e]=L[i]-1;
}
if(n==1) {
puts("1");
return;
}
sort(E+1,E+1+e),e=unique(E+1,E+1+e)-E-1;
For(i,1,e) D[i]=W[i]=F[i]=0;
F[e]=E[e];
For(i,1,n) {
int l=lower_bound(E+1,E+1+e,L[i]-1)-E;
int r=lower_bound(E+1,E+1+e,R[i])-E;
if(r==E[e]) ml=L[i];
else sr=max(sr,R[i]);
D[l+1]++,D[r+1]--,W[r]++;
F[l]=L[i]-1;
}
if(W[e]>1) sr=E[e];
Dor(i,e,1) if(!F[i]) F[i]=F[i+1];
LL ans=0;
int p=0;
For(i,2,e) {
D[i]+=D[i-1];
if(!D[i]) {
if(p>=2&&p<=n-2) {
ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
}
else if(p==1&&n>=3) {
int c=0,s=0,l=E[e];
For(j,1,n) {
if(L[j]>E[i]) {
l=min(l,L[j]);
++c;
s+=R[j]-L[j];
}
if(c>=3) ans+=1LL*(E[i]-E[i-1])*(E[e]-l);
else ans+=1LL*(E[i]-E[i-1])*s;
}
}
}
else {
if(D[i]>1||p&&i!=e) {
ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
}
else {
int r=E[e];
if(D[i]==1&&ml<=E[i]) {
r=sr;
}
ans+=1LL*(E[i]-E[i-1])*max(0,sr-F[i]);
}
}
p+=W[i];
}
printf("%lld\n",ans);
}
int main() {
int T; scanf("%d",&T);
while(T--) magic();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5968kb
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: 3ms
memory: 7940kb
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: 7904kb
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'