QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630791#5144. Set of IntervalsqkyWA 15ms3696kbC++17893b2024-10-11 20:25:512024-10-11 20:25:51

Judging History

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

  • [2024-10-11 20:25:51]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3696kb
  • [2024-10-11 20:25:51]
  • 提交

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;
        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: 3644kb

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: 3696kb

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: 15ms
memory: 3636kb

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
-8674795744527268
230263230414266279
75195165925255965
-147589701780048260
32977435735183263
316367547533445965
56483863859672889
35036765368929163
36132096841419954
57797703310407226
307857554310722843
261703336965133219
-92803064481147660
63833225117266922
49445284985875548
20811...

result:

wrong answer 2nd numbers differ - expected: '18821102290156188', found: '-8674795744527268'