Submission #902223

# Submission time Handle Problem Language Result Execution time Memory
902223 2024-01-10T07:21:37 Z 089487 Joker (BOI20_joker) C++14
100 / 100
567 ms 21556 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse4,abm,avx,popcnt")
#include<bits/stdc++.h>
//#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define F first
#define S second
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
    cout<<a<<" ",debug(b...);
}
const int N=5e5+2;
pii e[N];
int p[N];
int sz[N];
void init(int n){
    rep(i,1,n) p[i]=i,sz[i]=1;
}
int fp(int x){
    for(;x!=p[x];x=p[x]) ;
    return p[x];
}
int ans[N];
stack<tuple<int,int,int>> state;
int n,m;
void _Union(int a,int b){
    a=fp(a);
    b=fp(b);
    if(a==b) {
        state.push(make_tuple(-1,-1,-1));
        return ;
    }
    //assert(a!=b);
    if(sz[a]<sz[b]) swap(a,b);
    state.push(make_tuple(a,sz[a],b));
    p[b]=a;
    sz[a]+=sz[b];
    return ;
}
bool Union(int a,int b){
    int fa=fp(a);
    int fb=fp(b);
    if(fa==fb) return false;
    _Union(fa,b+n);
    _Union(fb,a+n);
    return true;
}
void undo(){
    auto [a,sza,b]=state.top();
    state.pop();
    if(a==-1) return ;
    sz[a]=sza;
    p[b]=b;
}
void solve(int l,int r,int vl,int vr){
    if(l>r||vl>vr) return ;
    //debug("solve",l,r,vl,vr);
    if(vl==vr){
        rep(i,l,r) ans[i]=vl;
        return ;
    }
    int mid=(l+r)>>1;
    ans[mid]=vr;
    for(int i=mid;i<=vr;i++){
        if(i==r+1) i=max(i,vl);
        if(!Union(e[i].F,e[i].S)){
            ans[mid]=i-1;
            break;
        }
    }
    assert(ans[mid]>=vl&&ans[mid]<=vr);
    // [r+1,vl-1] is done
    for(int i=ans[mid];i>=max(vl,mid);i--){
        undo();
        undo();
    }
    solve(l,mid-1,vl,ans[mid]);
    rep(i,mid,min(r,vl-1)){
        undo();
        undo();
    }
    rep(i,max(r+1,vl),ans[mid]-1) Union(e[i].F,e[i].S);
    solve(mid+1,r,ans[mid],vr);
    rep(i,max(r+1,vl),ans[mid]-1) undo(),undo();
}
signed main(){
	quick
    int q;
    cin>>n>>m>>q;
    init(n*2);
    rep(i,0,m-1){
        cin>>e[i].F>>e[i].S;
        e[i+m]=e[i];
    }
    solve(0,m,0,m*2-1);
    /*rep(i,0,m-1){
        cout<<ans[i]<<" \n"[i==m-1];
    }
    rep(i,0,m-1){
        init(2*n);
        ans[i]=-1;
        rep(j,i,m-1){
            if(Union(e[j].F,e[j].S)) ans[i]=j;
            else break;
        }
        cout<<ans[i]<<" \n"[i==m-1];
    }*/
    string Ans[2]={"YES","NO"};
    while(q--){
        int l,r;
        cin>>l>>r;
        --l,--r;
        cout<<Ans[(ans[r+1]>=l+m-1)]<<"\n";
    }
}

Compilation message

Joker.cpp: In function 'void undo()':
Joker.cpp:61:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     auto [a,sza,b]=state.top();
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6504 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6660 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6608 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 1 ms 6500 KB Output is correct
22 Correct 1 ms 6504 KB Output is correct
23 Correct 1 ms 6504 KB Output is correct
24 Correct 1 ms 6600 KB Output is correct
25 Correct 1 ms 6504 KB Output is correct
26 Correct 1 ms 6504 KB Output is correct
27 Correct 1 ms 6516 KB Output is correct
28 Correct 2 ms 6504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6504 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6660 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6608 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 1 ms 6500 KB Output is correct
22 Correct 1 ms 6504 KB Output is correct
23 Correct 1 ms 6504 KB Output is correct
24 Correct 1 ms 6600 KB Output is correct
25 Correct 1 ms 6504 KB Output is correct
26 Correct 1 ms 6504 KB Output is correct
27 Correct 1 ms 6516 KB Output is correct
28 Correct 2 ms 6504 KB Output is correct
29 Correct 3 ms 6504 KB Output is correct
30 Correct 3 ms 6504 KB Output is correct
31 Correct 3 ms 6632 KB Output is correct
32 Correct 3 ms 6504 KB Output is correct
33 Correct 2 ms 6504 KB Output is correct
34 Correct 3 ms 6504 KB Output is correct
35 Correct 4 ms 6504 KB Output is correct
36 Correct 4 ms 6504 KB Output is correct
37 Correct 4 ms 6504 KB Output is correct
38 Correct 3 ms 6760 KB Output is correct
39 Correct 3 ms 6504 KB Output is correct
40 Correct 3 ms 6504 KB Output is correct
41 Correct 3 ms 6504 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6684 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6496 KB Output is correct
47 Correct 3 ms 6624 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6504 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 3 ms 6488 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 3 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 290 ms 16476 KB Output is correct
4 Correct 531 ms 21556 KB Output is correct
5 Correct 325 ms 18616 KB Output is correct
6 Correct 250 ms 16524 KB Output is correct
7 Correct 223 ms 16512 KB Output is correct
8 Correct 330 ms 15748 KB Output is correct
9 Correct 396 ms 15844 KB Output is correct
10 Correct 464 ms 15664 KB Output is correct
11 Correct 353 ms 16436 KB Output is correct
12 Correct 350 ms 15888 KB Output is correct
13 Correct 281 ms 15720 KB Output is correct
14 Correct 384 ms 16408 KB Output is correct
15 Correct 424 ms 16408 KB Output is correct
16 Correct 480 ms 16096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6504 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6660 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6608 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 1 ms 6500 KB Output is correct
22 Correct 1 ms 6504 KB Output is correct
23 Correct 1 ms 6504 KB Output is correct
24 Correct 1 ms 6600 KB Output is correct
25 Correct 1 ms 6504 KB Output is correct
26 Correct 1 ms 6504 KB Output is correct
27 Correct 1 ms 6516 KB Output is correct
28 Correct 2 ms 6504 KB Output is correct
29 Correct 290 ms 16476 KB Output is correct
30 Correct 531 ms 21556 KB Output is correct
31 Correct 325 ms 18616 KB Output is correct
32 Correct 250 ms 16524 KB Output is correct
33 Correct 223 ms 16512 KB Output is correct
34 Correct 330 ms 15748 KB Output is correct
35 Correct 396 ms 15844 KB Output is correct
36 Correct 464 ms 15664 KB Output is correct
37 Correct 353 ms 16436 KB Output is correct
38 Correct 350 ms 15888 KB Output is correct
39 Correct 281 ms 15720 KB Output is correct
40 Correct 384 ms 16408 KB Output is correct
41 Correct 424 ms 16408 KB Output is correct
42 Correct 480 ms 16096 KB Output is correct
43 Correct 355 ms 16588 KB Output is correct
44 Correct 567 ms 21460 KB Output is correct
45 Correct 369 ms 17912 KB Output is correct
46 Correct 248 ms 16756 KB Output is correct
47 Correct 308 ms 16656 KB Output is correct
48 Correct 447 ms 16476 KB Output is correct
49 Correct 424 ms 16116 KB Output is correct
50 Correct 340 ms 16732 KB Output is correct
51 Correct 349 ms 16340 KB Output is correct
52 Correct 344 ms 17072 KB Output is correct
53 Correct 272 ms 16552 KB Output is correct
54 Correct 350 ms 16880 KB Output is correct
55 Correct 387 ms 16960 KB Output is correct
56 Correct 438 ms 16384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6504 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6660 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6608 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 1 ms 6500 KB Output is correct
22 Correct 1 ms 6504 KB Output is correct
23 Correct 1 ms 6504 KB Output is correct
24 Correct 1 ms 6600 KB Output is correct
25 Correct 1 ms 6504 KB Output is correct
26 Correct 1 ms 6504 KB Output is correct
27 Correct 1 ms 6516 KB Output is correct
28 Correct 2 ms 6504 KB Output is correct
29 Correct 3 ms 6504 KB Output is correct
30 Correct 3 ms 6504 KB Output is correct
31 Correct 3 ms 6632 KB Output is correct
32 Correct 3 ms 6504 KB Output is correct
33 Correct 2 ms 6504 KB Output is correct
34 Correct 3 ms 6504 KB Output is correct
35 Correct 4 ms 6504 KB Output is correct
36 Correct 4 ms 6504 KB Output is correct
37 Correct 4 ms 6504 KB Output is correct
38 Correct 3 ms 6760 KB Output is correct
39 Correct 3 ms 6504 KB Output is correct
40 Correct 3 ms 6504 KB Output is correct
41 Correct 3 ms 6504 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6684 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6496 KB Output is correct
47 Correct 3 ms 6624 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6504 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 3 ms 6488 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 3 ms 6488 KB Output is correct
55 Correct 263 ms 14212 KB Output is correct
56 Correct 480 ms 21548 KB Output is correct
57 Correct 260 ms 16196 KB Output is correct
58 Correct 193 ms 14292 KB Output is correct
59 Correct 328 ms 14020 KB Output is correct
60 Correct 353 ms 14376 KB Output is correct
61 Correct 300 ms 14256 KB Output is correct
62 Correct 294 ms 14532 KB Output is correct
63 Correct 252 ms 13964 KB Output is correct
64 Correct 341 ms 14136 KB Output is correct
65 Correct 363 ms 14276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6612 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6612 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6504 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6660 KB Output is correct
16 Correct 1 ms 6744 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6608 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 1 ms 6500 KB Output is correct
22 Correct 1 ms 6504 KB Output is correct
23 Correct 1 ms 6504 KB Output is correct
24 Correct 1 ms 6600 KB Output is correct
25 Correct 1 ms 6504 KB Output is correct
26 Correct 1 ms 6504 KB Output is correct
27 Correct 1 ms 6516 KB Output is correct
28 Correct 2 ms 6504 KB Output is correct
29 Correct 3 ms 6504 KB Output is correct
30 Correct 3 ms 6504 KB Output is correct
31 Correct 3 ms 6632 KB Output is correct
32 Correct 3 ms 6504 KB Output is correct
33 Correct 2 ms 6504 KB Output is correct
34 Correct 3 ms 6504 KB Output is correct
35 Correct 4 ms 6504 KB Output is correct
36 Correct 4 ms 6504 KB Output is correct
37 Correct 4 ms 6504 KB Output is correct
38 Correct 3 ms 6760 KB Output is correct
39 Correct 3 ms 6504 KB Output is correct
40 Correct 3 ms 6504 KB Output is correct
41 Correct 3 ms 6504 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6684 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6496 KB Output is correct
47 Correct 3 ms 6624 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6504 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 3 ms 6488 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 3 ms 6492 KB Output is correct
54 Correct 3 ms 6488 KB Output is correct
55 Correct 290 ms 16476 KB Output is correct
56 Correct 531 ms 21556 KB Output is correct
57 Correct 325 ms 18616 KB Output is correct
58 Correct 250 ms 16524 KB Output is correct
59 Correct 223 ms 16512 KB Output is correct
60 Correct 330 ms 15748 KB Output is correct
61 Correct 396 ms 15844 KB Output is correct
62 Correct 464 ms 15664 KB Output is correct
63 Correct 353 ms 16436 KB Output is correct
64 Correct 350 ms 15888 KB Output is correct
65 Correct 281 ms 15720 KB Output is correct
66 Correct 384 ms 16408 KB Output is correct
67 Correct 424 ms 16408 KB Output is correct
68 Correct 480 ms 16096 KB Output is correct
69 Correct 355 ms 16588 KB Output is correct
70 Correct 567 ms 21460 KB Output is correct
71 Correct 369 ms 17912 KB Output is correct
72 Correct 248 ms 16756 KB Output is correct
73 Correct 308 ms 16656 KB Output is correct
74 Correct 447 ms 16476 KB Output is correct
75 Correct 424 ms 16116 KB Output is correct
76 Correct 340 ms 16732 KB Output is correct
77 Correct 349 ms 16340 KB Output is correct
78 Correct 344 ms 17072 KB Output is correct
79 Correct 272 ms 16552 KB Output is correct
80 Correct 350 ms 16880 KB Output is correct
81 Correct 387 ms 16960 KB Output is correct
82 Correct 438 ms 16384 KB Output is correct
83 Correct 263 ms 14212 KB Output is correct
84 Correct 480 ms 21548 KB Output is correct
85 Correct 260 ms 16196 KB Output is correct
86 Correct 193 ms 14292 KB Output is correct
87 Correct 328 ms 14020 KB Output is correct
88 Correct 353 ms 14376 KB Output is correct
89 Correct 300 ms 14256 KB Output is correct
90 Correct 294 ms 14532 KB Output is correct
91 Correct 252 ms 13964 KB Output is correct
92 Correct 341 ms 14136 KB Output is correct
93 Correct 363 ms 14276 KB Output is correct
94 Correct 323 ms 17288 KB Output is correct
95 Correct 395 ms 18468 KB Output is correct
96 Correct 290 ms 19492 KB Output is correct
97 Correct 219 ms 17444 KB Output is correct
98 Correct 247 ms 17532 KB Output is correct
99 Correct 327 ms 17348 KB Output is correct
100 Correct 403 ms 17148 KB Output is correct
101 Correct 297 ms 17464 KB Output is correct
102 Correct 398 ms 17640 KB Output is correct
103 Correct 341 ms 17300 KB Output is correct
104 Correct 333 ms 17420 KB Output is correct
105 Correct 399 ms 17720 KB Output is correct
106 Correct 418 ms 17112 KB Output is correct
107 Correct 187 ms 20244 KB Output is correct
108 Correct 289 ms 17036 KB Output is correct
109 Correct 298 ms 17096 KB Output is correct
110 Correct 333 ms 17192 KB Output is correct
111 Correct 324 ms 17180 KB Output is correct
112 Correct 308 ms 17044 KB Output is correct
113 Correct 296 ms 17176 KB Output is correct
114 Correct 291 ms 17036 KB Output is correct
115 Correct 329 ms 17200 KB Output is correct
116 Correct 317 ms 17124 KB Output is correct