QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67998#5144. Set of IntervalsKostlinWA 8ms3520kbC++142.4kb2022-12-13 20:58:452022-12-13 20:58:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-13 20:58:46]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3520kb
  • [2022-12-13 20:58:45]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
#define fi first
#define sc second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int N=1e5+5,oo=1e9,mod=1e9+7;
inline int read() {
    int x=0,flag=0;char ch=getchar();
    while(ch<'0'||ch>'9') {flag|=(ch=='-');ch=getchar();}
    while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
inline void swp(int &x,int &y) {x^=y^=x^=y;}
inline int as(int x) {return x>0?x:-x;}

int n,c[N<<1],L[N],R[N],t[N<<1],val[N<<1];
int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    freopen("1.out","w",stdout);
#endif
    int TT=read();
    while(TT--) {
        n=read(); c[0]=0;
        for(int i=1;i<=n;++i) {
            L[i]=read(),R[i]=read();
            c[++c[0]]=L[i];c[++c[0]]=R[i]+1;
        }
        sort(c+1,c+c[0]+1); c[0]=unique(c+1,c+c[0]+1)-c-1;
        if(n==1) {
            printf("1\n");
            continue;
        }
        if(c[0]==2) {
            printf("%lld\n",1ll*(c[2]-c[1])*(c[2]-c[1]-1)/2);
            continue;
        }
        int qwq=0,qaq=0,ovo=c[0]+1,fl=0;
        for(int i=1;i<=n;++i) {
            L[i]=lower_bound(c+1,c+c[0]+1,L[i])-c,
            R[i]=lower_bound(c+1,c+c[0]+1,R[i]+1)-c;
            if(R[i]==c[0]) qwq=i;
            else qaq=mx(qaq,R[i]);
            if(L[i]!=1) ovo=mn(ovo,L[i]);
            if(L[i]==1&&R[i]==c[0]) fl=1;
            ++t[L[i]];--t[R[i]];
            val[L[i]]^=i;val[R[i]]^=i;
        }
        for(int i=1;i<=c[0];++i)
            t[i]+=t[i-1],val[i]^=val[i-1];
        ll ans=0;
        for(int i=2;i<=c[0]-2;++i) {
            if(!t[i]) continue;
            if(t[i]==1&&val[i]==qwq) ans+=1ll*(c[i+1]-c[i])*(c[qaq]-c[i]+c[qaq]-c[i+1]+1)/2;
            else ans+=1ll*(c[i+1]-c[i])*(c[c[0]]-c[i]+c[c[0]]-c[i+1]+1)/2;
        }
        if(t[1]>1) ans+=1ll*(c[2]-c[1])*(c[c[0]]-c[1]-1+c[c[0]]-c[2])/2;
        else {
            if(fl&&t[c[0]-1]==1) ans+=1ll*(c[qaq]-c[ovo])*(c[2]-c[1]);
            else ans+=1ll*(c[qwq]-c[ovo])*(c[2]-c[1]);
        }
        if(t[c[0]-1]>1) ans+=1ll*(c[c[0]]-c[c[0]-1])*(c[c[0]]-c[c[0]-1]-1)/2; 
        printf("%lld\n",ans);
        for(int i=1;i<=c[0];++i) t[i]=val[i]=0;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3520kb

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: 1ms
memory: 3504kb

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

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:

42453323358192963
-89832884696785566
113106465395021350
10829759765438042
-12216725958870437
1256173738072245
207604390961669335
7626318013370983
-7817177595491395
2619243064582742
22573394550901124
143688904076043844
166852999464956370
-182501560188935442
25007962023132375
-1964565133790688
-103552...

result:

wrong answer 1st numbers differ - expected: '87849603321470913', found: '42453323358192963'