QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644860#9465. 基础 01 练习题zjy000110 622ms247228kbC++173.8kb2024-10-16 15:41:162024-10-16 15:41:16

Judging History

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

  • [2024-10-16 15:41:16]
  • 评测
  • 测评结果:10
  • 用时:622ms
  • 内存:247228kb
  • [2024-10-16 15:41:16]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=2e5+5,M=N*80,Mod=998244353,INF=1e8;
int n,m,typ,rt,cnt;
LL ans;
int pw2[N];
int T[M],L[M],R[M],S[M];
vector<pair<int,int>>E[N],U[N];
int mn[N*4][2],mx[N*4][2],tg[N*4];
__gnu_pbds::priority_queue<int>Q[N];
int RT[N],id[N],pos[N],fd[N],g[N],sz[N];
inline int find(const int&x){
    return x==fd[x]?x:fd[x]=find(fd[x]);
}
inline void flip(int&p,int l,int r,int x,int y){
    const int q=p;
    p=++cnt,L[p]=L[q],R[p]=R[q],S[p]=S[q],T[p]=T[q];
    if(x<=l&&r<=y){
        T[p]=(pw2[r-l+1]-1-T[p]+Mod)%Mod,S[p]^=1;
        return;
    }
    const int mid=(l+r)>>1;
    if(x<=mid)flip(L[p],l,mid,x,y);
    if(mid<y)flip(R[p],mid+1,r,x,y);
    T[p]=(1ll*T[L[p]]*pw2[r-mid]+T[R[p]])%Mod;
    if(S[p])T[p]=(pw2[r-l+1]-1-T[p]+Mod)%Mod;
}
inline int cmp(int p,int q,int l,int r,int ps=0,int qs=0){
    if((ps^qs)?((T[p]+T[q]-pw2[r-l+1]+1)%Mod==0):(T[p]==T[q]))return 0;
    if(l==r)return (ps?1-T[p]:T[p])<(qs?1-T[q]:T[q]);
    const int mid=(l+r)>>1;
    ps^=S[p],qs^=S[q];
    if((ps^qs)?((T[L[p]]+T[L[q]]-pw2[r-l+1]+1)%Mod==0):(T[L[p]]==T[L[q]]))return cmp(R[p],R[q],mid+1,r,ps,qs);
    return cmp(L[p],L[q],l,mid,ps,qs);
}
inline void rev(int p){
    swap(mn[p][0],mn[p][1]),swap(mx[p][0],mx[p][1]),tg[p]^=1;
}
inline void pushup(int p){
    const int ls=p*2,rs=p*2+1;
    mn[p][0]=min(mn[ls][0],mn[rs][0]);
    mn[p][1]=min(mn[ls][1],mn[rs][1]);
    mx[p][0]=max(mx[ls][0],mx[rs][0]);
    mx[p][1]=max(mx[ls][1],mx[rs][1]);
}
inline void build(int p,int l,int r){
    if(l==r){
        mn[p][0]=pos[l],mx[p][0]=pos[l];
        mn[p][1]=INF,mx[p][1]=-INF;
        return;
    }
    const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
    build(ls,l,mid),build(rs,mid+1,r);
    pushup(p);
}
inline void flipn(int p,int l,int r,int x,int y){
    if(x<=l&&r<=y)return rev(p);
    const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
    if(tg[p])rev(ls),rev(rs),tg[p]=0;
    if(x<=mid)flipn(ls,l,mid,x,y);
    if(mid<y)flipn(rs,mid+1,r,x,y);
    pushup(p);
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m>>typ,pw2[0]=1;
    for(int i=1;i<=n;++i)pw2[i]=pw2[i-1]*2%Mod;
    for(int i=1;i<=m;++i){
        int l,r,d,u;cin>>l>>r>>d>>u;
        E[l].emplace_back(d,u);
        E[r+1].emplace_back(d,u);
        U[d].emplace_back(l,r);
        U[u+1].emplace_back(l,r);
    }
    for(int i=1;i<=n;++i){
        for(auto [l,r]:E[i])flip(rt,1,n,l,r);
        RT[i]=rt,id[i]=i;
    }
    stable_sort(id+1,id+n+1,[&](const int&x,const int&y){
        return cmp(RT[x],RT[y],1,n);
    });
    for(int i=1;i<=n;++i)pos[id[i]]=i;
    iota(fd+1,fd+n+1,1),fill(sz+1,sz+n+1,1);
    build(1,1,n);
    for(int i=1;i<=n;++i){
        ans+=n;
        for(auto [l,r]:U[i])flipn(1,1,n,l,r);
        int l=mn[1][1],r=mx[1][0];
        if(l<=r){
            int x=find(r);
            ans+=max(1ll*sz[x]*g[x]-1,0ll);
            ++g[x];
            ans-=max(1ll*sz[x]*g[x]-1,0ll);
            while(x>l){
                int y=find(x-1);
                ans+=max(1ll*sz[x]*g[x]-1,0ll)+max(1ll*sz[y]*g[y]-1,0ll);
                fd[x]=y,sz[y]+=sz[x],g[y]+=g[x];
                Q[y].join(Q[x]);
                while(!Q[y].empty()&&Q[y].top()>=y)Q[y].pop(),++g[y];
                ans-=max(1ll*sz[y]*g[y]-1,0ll),x=y;
            }
        }
        else if(l<=n&&r>=1){
            int x=find(l);
            if(x<=r){
                ans+=max(1ll*sz[x]*g[x]-1,0ll);
                ++g[x];
                ans-=max(1ll*sz[x]*g[x]-1,0ll);
            }
            else Q[x].push(r);
        }
        if(typ||i==n)cout<<ans<<" \n"[i==n];
    }
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 28328kb

input:

4 1000 0
2 3 1 2
1 3 1 3
1 2 1 2
1 2 3 4
1 4 2 4
1 3 1 2
1 4 1 2
1 3 1 4
3 3 2 3
1 2 2 4
4 4 1 3
3 3 3 4
3 4 3 4
2 3 1 1
1 2 2 4
1 4 3 4
3 4 1 2
1 2 2 3
3 4 3 3
1 2 4 4
4 4 2 4
1 4 1 1
1 1 1 3
2 3 2 3
1 1 2 4
2 3 2 4
3 3 1 4
3 3 3 3
1 3 3 3
2 3 2 4
3 3 2 2
1 3 2 4
1 3 1 2
3 4 1 2
2 3 1 3
1 1 1 2
1 2...

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 5
Accepted
time: 0ms
memory: 30420kb

input:

4 1000 0
1 4 3 3
2 3 4 4
3 4 3 4
3 4 1 2
1 4 2 4
2 3 1 3
3 4 2 4
2 3 3 3
3 4 1 3
1 3 1 4
2 3 1 3
1 1 2 2
1 4 3 4
1 4 1 3
1 2 3 4
1 2 1 2
2 3 1 4
2 2 2 2
1 3 1 3
2 2 2 4
1 2 1 4
1 1 1 1
1 2 3 4
4 4 1 3
2 4 1 3
1 1 1 3
1 4 2 2
2 3 1 2
2 2 1 2
1 2 1 4
1 4 2 4
1 2 1 3
1 2 1 3
2 4 2 2
1 2 1 1
1 2 1 3
2 4...

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 28384kb

input:

4 1000 0
1 4 1 2
1 4 2 2
1 4 3 4
2 4 4 4
2 3 3 4
2 4 2 4
1 2 2 2
4 4 2 4
1 3 1 3
1 4 1 4
3 3 3 4
4 4 2 3
2 3 1 4
2 2 1 3
2 3 2 4
2 2 1 4
1 2 2 3
1 4 1 3
4 4 1 4
3 4 1 4
1 2 1 2
1 2 1 3
2 2 3 3
1 2 1 4
1 1 1 4
2 2 1 4
1 4 3 4
2 4 2 4
2 2 1 4
3 4 1 3
2 3 2 4
1 3 1 4
1 3 1 4
3 3 1 3
1 2 1 3
3 3 1 4
1 4...

output:

1

result:

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

Subtask #2:

score: 10
Accepted

Test #4:

score: 10
Accepted
time: 108ms
memory: 109024kb

input:

50 200000 0
1 45 2 6
29 44 2 6
31 37 2 50
2 37 1 19
7 13 8 38
38 46 19 38
10 30 30 46
22 42 1 45
5 35 24 27
10 36 19 31
20 47 17 35
7 9 23 42
15 26 31 42
7 8 7 42
1 26 33 48
2 5 30 36
17 44 21 44
5 44 24 36
19 47 15 17
29 36 2 42
31 34 11 41
9 24 12 30
30 43 8 20
2 12 13 20
11 12 10 15
14 22 3 29
2 ...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 10
Accepted
time: 7ms
memory: 30308kb

input:

50 70 0
1 50 1 50
24 50 1 1
50 50 2 2
34 50 3 3
36 50 4 4
32 50 5 5
18 50 6 6
12 50 7 7
6 50 8 8
28 50 9 9
38 50 10 10
4 50 11 11
26 50 12 12
14 50 13 13
46 50 14 14
2 50 15 15
8 50 16 16
44 50 17 17
10 50 18 18
30 50 19 19
22 50 20 20
48 50 21 21
20 50 22 22
42 50 23 23
40 50 24 24
16 50 25 25
16 5...

output:

2280

result:

ok 1 number(s): "2280"

Test #6:

score: 10
Accepted
time: 3ms
memory: 28304kb

input:

50 100 0
2 49 1 1
23 28 2 2
19 32 3 3
21 30 4 4
20 31 5 5
22 29 6 6
12 39 7 7
15 36 8 8
7 44 9 9
3 48 10 10
10 41 11 11
5 46 12 12
14 37 13 13
13 38 14 14
4 47 15 15
6 45 16 16
17 34 17 17
25 26 18 18
1 50 19 19
9 42 20 20
11 40 21 21
16 35 22 22
24 27 23 23
8 43 24 24
18 33 25 25
11 40 26 26
14 37 ...

output:

339

result:

ok 1 number(s): "339"

Test #7:

score: 10
Accepted
time: 0ms
memory: 28396kb

input:

50 500 0
1 2 1 14
3 4 1 3
5 6 1 12
7 8 1 9
9 10 1 15
11 12 1 11
13 14 1 13
15 16 1 17
17 18 1 16
19 20 1 20
21 22 1 2
23 24 1 10
25 26 1 4
27 28 1 8
29 30 1 19
31 32 1 21
33 34 1 24
35 36 1 23
37 38 1 6
39 40 1 18
41 42 1 25
43 44 1 5
45 46 1 22
47 48 1 1
49 50 1 7
35 36 26 26
41 42 26 26
27 28 27 2...

output:

51

result:

ok 1 number(s): "51"

Subtask #3:

score: 0
Wrong Answer

Test #8:

score: 10
Accepted
time: 353ms
memory: 227616kb

input:

5000 200000 0
1438 2561 3478 4930
1740 4634 87 3003
590 3275 1376 1681
2035 2793 2004 4945
567 3159 550 4470
61 3039 3431 3519
2654 3834 3460 4960
591 3560 409 443
345 2599 746 2891
1288 4570 1577 4402
249 377 1951 4534
2411 2455 294 1192
1679 3153 1645 4259
1735 1856 601 668
477 4881 411 2094
424 1...

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 10
Accepted
time: 104ms
memory: 100096kb

input:

5000 200000 0
4336 5000 1 1
686 5000 2 2
3130 5000 3 3
672 5000 4 4
1664 5000 5 5
1480 5000 6 6
1326 5000 7 7
3726 5000 8 8
4170 5000 9 9
4794 5000 10 10
3374 5000 11 11
1836 5000 12 12
310 5000 13 13
2146 5000 14 14
3266 5000 15 15
820 5000 16 16
1152 5000 17 17
2876 5000 18 18
134 5000 19 19
828 5...

output:

24995

result:

ok 1 number(s): "24995"

Test #10:

score: 10
Accepted
time: 123ms
memory: 100116kb

input:

5000 200000 0
1410 5000 1 1
3340 5000 2 2
4202 5000 3 3
4450 5000 4 4
914 5000 5 5
4514 5000 6 6
4 5000 7 7
238 5000 8 8
3182 5000 9 9
3302 5000 10 10
2136 5000 11 11
1504 5000 12 12
3204 5000 13 13
2078 5000 14 14
4026 5000 15 15
3690 5000 16 16
4430 5000 17 17
1304 5000 18 18
2156 5000 19 19
4154 ...

output:

10000

result:

ok 1 number(s): "10000"

Test #11:

score: 10
Accepted
time: 148ms
memory: 121744kb

input:

5000 200000 0
1556 3445 1 1
1803 3198 2 2
790 4211 3 3
564 4437 4 4
1128 3873 5 5
129 4872 6 6
2062 2939 7 7
1480 3521 8 8
1252 3749 9 9
942 4059 10 10
111 4890 11 11
915 4086 12 12
1575 3426 13 13
2186 2815 14 14
392 4609 15 15
1689 3312 16 16
492 4509 17 17
866 4135 18 18
381 4620 19 19
92 4909 20...

output:

34989

result:

ok 1 number(s): "34989"

Test #12:

score: 10
Accepted
time: 148ms
memory: 146296kb

input:

5000 200000 0
1 1 2330 2671
2 2 789 4212
3 3 1593 3408
4 4 438 4563
5 5 2048 2953
6 6 491 4510
7 7 578 4423
8 8 770 4231
9 9 482 4519
10 10 395 4606
11 11 1960 3041
12 12 1289 3712
13 13 621 4380
14 14 2235 2766
15 15 916 4085
16 16 781 4220
17 17 1440 3561
18 18 902 4099
19 19 1998 3003
20 20 641 4...

output:

49977

result:

ok 1 number(s): "49977"

Test #13:

score: 0
Wrong Answer
time: 265ms
memory: 196124kb

input:

5000 200000 0
1 661 1 2
1 1385 3 4
1 225 5 6
1 1833 7 8
1 58 9 10
1 2064 11 12
1 235 13 14
1 1918 15 16
1 2137 17 18
1 538 19 20
1 513 21 22
1 1405 23 24
1 1376 25 26
1 1711 27 28
1 165 29 30
1 209 31 32
1 68 33 34
1 1864 35 36
1 1455 37 38
1 425 39 40
1 669 41 42
1 2326 43 44
1 133 45 46
1 2257 47 ...

output:

1

result:

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

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 316ms
memory: 228152kb

input:

5000 200000 1
565 4401 1659 1826
429 1640 2999 3495
572 3994 9 3863
3844 4284 2307 3144
1054 1943 358 2592
727 4248 29 1171
1685 2392 4559 4929
1149 2787 1204 1947
2349 2619 405 998
1910 2786 25 1275
912 3475 4384 4387
3822 4895 1849 4548
3082 4749 3457 4220
3174 4885 117 1085
2517 3919 4325 4869
17...

output:

5000 5653 3715 1781 1031 823 540 89 82 21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:

wrong answer 8th numbers differ - expected: '185', found: '89'

Subtask #5:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 566ms
memory: 175648kb

input:

200000 200000 1
1 2 1 6
3 4 1 1
5 6 1 5
7 8 1 3
9 10 1 3
11 12 1 6
13 14 1 5
15 16 1 6
17 18 1 6
19 20 1 1
21 22 1 4
23 24 1 5
25 26 1 2
27 28 1 4
29 30 1 3
31 32 1 2
33 34 1 6
35 36 1 3
37 38 1 2
39 40 1 2
41 42 1 3
43 44 1 1
45 46 1 2
47 48 1 3
49 50 1 4
51 52 1 5
53 54 1 1
55 56 1 5
57 58 1 5
59 ...

output:

200000 200007 200009 200001 200001 200001 200001 400001 400001 600001 800001 800001 1000001 1200001 1400001 1600001 1600001 1800001 2000001 2000001 2200001 2400001 2400001 2600001 2800001 3000001 3200001 3400001 3600001 3600001 3800001 4000001 4200001 4400001 4600001 4800001 4800001 5000001 5200001 ...

result:

wrong answer 2nd numbers differ - expected: '400000', found: '200007'

Subtask #6:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

input:

200000 200000 0
91264 123676 6826 154505
121351 188051 108158 131448
65413 163961 26771 116304
93852 110556 34929 187363
31794 142162 33578 38712
26574 67763 178013 197235
46436 146042 95 122860
11683 50463 60177 195245
60862 194711 37817 97212
144366 176271 113551 171098
120095 170517 73555 167299
...

output:


result:


Subtask #7:

score: 0
Wrong Answer

Test #37:

score: 0
Wrong Answer
time: 622ms
memory: 247228kb

input:

100000 200000 1
1 22878 1 2
1 7957 3 4
1 21779 5 6
1 34321 7 8
1 41692 9 10
1 49473 11 12
1 10254 13 14
1 43995 15 16
1 46975 17 18
1 668 19 20
1 25996 21 22
1 24975 23 24
1 43259 25 26
1 4174 27 28
1 39330 29 30
1 35462 31 32
1 27523 33 34
1 5574 35 36
1 47955 37 38
1 47013 39 40
1 3846 41 42
1 276...

output:

100000 200000 171628 228837 231356 233383 192172 180577 96202 106891 31978 34885 32891 35421 20611 21985 23359 24733 26107 27481 28855 30229 31603 32977 34351 35725 37099 38473 39847 41221 42595 43969 45343 46717 48091 49465 50839 52213 53587 54961 56335 57709 59083 60457 52651 44529 38541 39361 401...

result:

wrong answer 3rd numbers differ - expected: '195499', found: '171628'