QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630899 | #5144. Set of Intervals | qky | WA | 16ms | 3696kb | C++17 | 1.2kb | 2024-10-11 20:51:56 | 2024-10-11 20:51:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll a[N],b[N];
int main(){
int t;cin>>t;
while(t--){
ll n;cin>>n;
for(int i=1;i<=n;i++){cin>>a[i];cin>>b[i];}
if(n==1){cout<<1<<endl;continue;}
ll ls=1e9,rs=0,lm=1e9,rm=0;
int lmi=0,rmi=0;
for(int i=1;i<=n;i++){
if(a[i]<lm){lmi=i;}
if(b[i]>rm){rmi=i;}
lm=min(lm,a[i]);
rm=max(rm,b[i]);
}
for(int i=1;i<=n;i++){
if(a[i]!=lm)ls=min(ls,a[i]);
if(b[i]!=rm)rs=max(rs,b[i]);
}
if(ls==1e9)ls=lm;
if(rs==0)rs=rm;
//cout<<ls<<" "<<rs<<endl;
//cout<<lm<<" "<<rm<<endl;
ll ans=0;
if(rs<ls){
ans=(rm-ls+1)*(rs-lm+1);
cout<<ans<<endl;
continue;
}
if(lmi==rmi){
ans=(rs-ls+1)*(rs-ls)/2+(rs-ls+1)*(rm-lm-rs+ls);
cout<<ans<<endl;
continue;
}
ans=(rm-lm+1)*(rm-lm)/2;
if(ls!=lm){
ans-=(ls-lm)*(ls-lm-1)/2;
}
if(rs!=rm){
ans-=(rm-rs)*(rm-rs-1)/2;
}
cout<<ans<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 10ms
memory: 3640kb
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: 11ms
memory: 3576kb
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: 16ms
memory: 3696kb
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 269965111370246655 187516336041444375 122087055515083130 166464628402586213 303666532800970347 176358932288144970 330593156050995465 62550768753522599 247444999637419584 223189919337023814 199454344726240709 186982464464105447 274043263510447662 200274422590053105 2387307446491590...
result:
wrong answer 9th numbers differ - expected: '59827455776692524', found: '62550768753522599'