QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630831#5144. Set of IntervalsqkyWA 9ms3644kbC++171017b2024-10-11 20:34:432024-10-11 20:34:44

Judging History

你现在查看的是最新测评结果

  • [2024-10-11 20:34:44]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:3644kb
  • [2024-10-11 20:34:43]
  • 提交

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;
        for(int i=1;i<=n;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;
        }
        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: 3604kb

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: 8ms
memory: 3580kb

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: 9ms
memory: 3644kb

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'