Submission #906408

# Submission time Handle Problem Language Result Execution time Memory
906408 2024-01-14T07:58:53 Z gaga999 Joker (BOI20_joker) C++17
100 / 100
542 ms 25128 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
const int N=200005;
const int M=500005;
const int INF=1e9;
const int mod=1e9+7;
vector<int> e1(N<<1),e2(N<<1);
vector<int> pa(N<<1),sz(N<<1,1);
vector<int> dp(N);
vector<tuple<int,int,int,int>> st;
vector<int> st1;
int valid=0;
int n,m,q;
int Find(int k){
    if(pa[k]==k){
        return k;
    }
    return Find(pa[k]);
}
void onion2(int a,int b){
    a=Find(a);
    b=Find(b);
    if(a==b){
        return;
    }
    if(sz[a]>sz[b]){
        swap(a,b);
    }
    st.push_back({a,pa[a],b,sz[b]});
    pa[a]=b;
    sz[b]+=sz[a];
}
int onion1(int a,int b){
    onion2(a,b+N);
    onion2(a+N,b);
    while(st.size()>st1.size()){
        st1.push_back(valid);
    }
    valid|=(Find(a)==Find(a+N));
    return valid;
}
int onion(int i){
    return onion1(e1[i],e2[i]);
}
void undo(){
    auto [a,b,c,d]=st.back();
    st.pop_back();
    pa[a]=b;
    sz[c]=d;
    valid=st1.back();
    st1.pop_back();
}
// | 1 2 3 4 | 5 6 7 8 
void dc(int l,int r,int a,int b){
    if(r<l)return;
    b=min(m,b);
    //cout<<l<<' '<<r<<' '<<a<<' '<<b<<endl;
    int mi=(l+r)>>1;
    int rec1=st.size();
    for(int i=l;i<mi;i++){
        onion(i);
    }
    int rec=st.size();
    if(valid){
        //cout<<mi<<endl;
        dp[mi]=b+1;
    }
    else{
        int last=b;
        for(int i=b;i>=a;i--){
            if(onion(i)){
                break;
            }
            last--;
        }
        dp[mi]=last;
    }
    while(st.size()>rec){
        undo();
    }
    onion(mi);
    dc(mi+1,r,dp[mi],b);
    while(st.size()>rec1){
        undo();
    }
    for(int i=b;i>dp[mi];i--){
        onion(i);
    }
    dc(l,mi-1,a,dp[mi]);
    while(st.size()>rec1){
        undo();
    }
}
int32_t main() {
    LCBorz;
    iota(all(pa),0);
    cin>>n>>m>>q;
    for(int i=1;i<=m;i++){
        cin>>e1[i]>>e2[i];
    }
    dc(1,m,1,m);
    for(int i=1;i<m;i++){
        assert(dp[i]<=dp[i+1]);
    }
    for(int i=0;i<q;i++){
        int a,b;cin>>a>>b;
        if(b>=dp[a]){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
    }
    
    return 0;
}
/*
3 15 10
1 2
2 3
3 1
1 2
2 3
3 1
1 2
2 3
3 1
1 2
2 3
3 1
1 2
2 3
3 1
*/

Compilation message

Joker.cpp: In function 'void dc(int, int, int, int)':
Joker.cpp:80:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |     while(st.size()>rec){
      |           ~~~~~~~~~^~~~
Joker.cpp:85:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |     while(st.size()>rec1){
      |           ~~~~~~~~~^~~~~
Joker.cpp:92:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |     while(st.size()>rec1){
      |           ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 4 ms 7516 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7312 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 4 ms 7516 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7312 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
29 Correct 7 ms 7516 KB Output is correct
30 Correct 7 ms 7680 KB Output is correct
31 Correct 8 ms 7676 KB Output is correct
32 Correct 7 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 8 ms 7684 KB Output is correct
35 Correct 10 ms 7772 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 7 ms 7516 KB Output is correct
38 Correct 8 ms 7512 KB Output is correct
39 Correct 7 ms 7688 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 8 ms 7436 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 8 ms 7516 KB Output is correct
44 Correct 9 ms 7876 KB Output is correct
45 Correct 7 ms 7552 KB Output is correct
46 Correct 8 ms 7512 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7512 KB Output is correct
49 Correct 8 ms 7516 KB Output is correct
50 Correct 8 ms 7684 KB Output is correct
51 Correct 7 ms 7516 KB Output is correct
52 Correct 7 ms 7516 KB Output is correct
53 Correct 9 ms 7512 KB Output is correct
54 Correct 8 ms 7896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 390 ms 16380 KB Output is correct
4 Correct 480 ms 21496 KB Output is correct
5 Correct 359 ms 22284 KB Output is correct
6 Correct 413 ms 17660 KB Output is correct
7 Correct 416 ms 16932 KB Output is correct
8 Correct 399 ms 14344 KB Output is correct
9 Correct 432 ms 16668 KB Output is correct
10 Correct 490 ms 22080 KB Output is correct
11 Correct 444 ms 16936 KB Output is correct
12 Correct 454 ms 22020 KB Output is correct
13 Correct 403 ms 12884 KB Output is correct
14 Correct 409 ms 14828 KB Output is correct
15 Correct 542 ms 20628 KB Output is correct
16 Correct 512 ms 22868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 4 ms 7516 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7312 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
29 Correct 390 ms 16380 KB Output is correct
30 Correct 480 ms 21496 KB Output is correct
31 Correct 359 ms 22284 KB Output is correct
32 Correct 413 ms 17660 KB Output is correct
33 Correct 416 ms 16932 KB Output is correct
34 Correct 399 ms 14344 KB Output is correct
35 Correct 432 ms 16668 KB Output is correct
36 Correct 490 ms 22080 KB Output is correct
37 Correct 444 ms 16936 KB Output is correct
38 Correct 454 ms 22020 KB Output is correct
39 Correct 403 ms 12884 KB Output is correct
40 Correct 409 ms 14828 KB Output is correct
41 Correct 542 ms 20628 KB Output is correct
42 Correct 512 ms 22868 KB Output is correct
43 Correct 384 ms 17560 KB Output is correct
44 Correct 523 ms 23096 KB Output is correct
45 Correct 453 ms 22388 KB Output is correct
46 Correct 381 ms 17500 KB Output is correct
47 Correct 416 ms 17564 KB Output is correct
48 Correct 454 ms 16812 KB Output is correct
49 Correct 494 ms 21784 KB Output is correct
50 Correct 418 ms 16456 KB Output is correct
51 Correct 415 ms 20736 KB Output is correct
52 Correct 466 ms 23020 KB Output is correct
53 Correct 388 ms 13316 KB Output is correct
54 Correct 525 ms 17760 KB Output is correct
55 Correct 494 ms 20480 KB Output is correct
56 Correct 498 ms 21748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 4 ms 7516 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7312 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
29 Correct 7 ms 7516 KB Output is correct
30 Correct 7 ms 7680 KB Output is correct
31 Correct 8 ms 7676 KB Output is correct
32 Correct 7 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 8 ms 7684 KB Output is correct
35 Correct 10 ms 7772 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 7 ms 7516 KB Output is correct
38 Correct 8 ms 7512 KB Output is correct
39 Correct 7 ms 7688 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 8 ms 7436 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 8 ms 7516 KB Output is correct
44 Correct 9 ms 7876 KB Output is correct
45 Correct 7 ms 7552 KB Output is correct
46 Correct 8 ms 7512 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7512 KB Output is correct
49 Correct 8 ms 7516 KB Output is correct
50 Correct 8 ms 7684 KB Output is correct
51 Correct 7 ms 7516 KB Output is correct
52 Correct 7 ms 7516 KB Output is correct
53 Correct 9 ms 7512 KB Output is correct
54 Correct 8 ms 7896 KB Output is correct
55 Correct 142 ms 16132 KB Output is correct
56 Correct 238 ms 21244 KB Output is correct
57 Correct 115 ms 21248 KB Output is correct
58 Correct 181 ms 16384 KB Output is correct
59 Correct 212 ms 15108 KB Output is correct
60 Correct 275 ms 20604 KB Output is correct
61 Correct 185 ms 14856 KB Output is correct
62 Correct 201 ms 22016 KB Output is correct
63 Correct 178 ms 12292 KB Output is correct
64 Correct 222 ms 16000 KB Output is correct
65 Correct 260 ms 21880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 5 ms 7516 KB Output is correct
3 Correct 4 ms 7516 KB Output is correct
4 Correct 4 ms 7512 KB Output is correct
5 Correct 5 ms 7516 KB Output is correct
6 Correct 4 ms 7516 KB Output is correct
7 Correct 4 ms 7516 KB Output is correct
8 Correct 4 ms 7516 KB Output is correct
9 Correct 4 ms 7516 KB Output is correct
10 Correct 4 ms 7516 KB Output is correct
11 Correct 5 ms 7516 KB Output is correct
12 Correct 4 ms 7516 KB Output is correct
13 Correct 4 ms 7516 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 6 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7312 KB Output is correct
19 Correct 5 ms 7516 KB Output is correct
20 Correct 4 ms 7516 KB Output is correct
21 Correct 4 ms 7516 KB Output is correct
22 Correct 5 ms 7516 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 5 ms 7516 KB Output is correct
25 Correct 5 ms 7512 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7512 KB Output is correct
28 Correct 4 ms 7512 KB Output is correct
29 Correct 7 ms 7516 KB Output is correct
30 Correct 7 ms 7680 KB Output is correct
31 Correct 8 ms 7676 KB Output is correct
32 Correct 7 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 8 ms 7684 KB Output is correct
35 Correct 10 ms 7772 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 7 ms 7516 KB Output is correct
38 Correct 8 ms 7512 KB Output is correct
39 Correct 7 ms 7688 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 8 ms 7436 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 8 ms 7516 KB Output is correct
44 Correct 9 ms 7876 KB Output is correct
45 Correct 7 ms 7552 KB Output is correct
46 Correct 8 ms 7512 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7512 KB Output is correct
49 Correct 8 ms 7516 KB Output is correct
50 Correct 8 ms 7684 KB Output is correct
51 Correct 7 ms 7516 KB Output is correct
52 Correct 7 ms 7516 KB Output is correct
53 Correct 9 ms 7512 KB Output is correct
54 Correct 8 ms 7896 KB Output is correct
55 Correct 390 ms 16380 KB Output is correct
56 Correct 480 ms 21496 KB Output is correct
57 Correct 359 ms 22284 KB Output is correct
58 Correct 413 ms 17660 KB Output is correct
59 Correct 416 ms 16932 KB Output is correct
60 Correct 399 ms 14344 KB Output is correct
61 Correct 432 ms 16668 KB Output is correct
62 Correct 490 ms 22080 KB Output is correct
63 Correct 444 ms 16936 KB Output is correct
64 Correct 454 ms 22020 KB Output is correct
65 Correct 403 ms 12884 KB Output is correct
66 Correct 409 ms 14828 KB Output is correct
67 Correct 542 ms 20628 KB Output is correct
68 Correct 512 ms 22868 KB Output is correct
69 Correct 384 ms 17560 KB Output is correct
70 Correct 523 ms 23096 KB Output is correct
71 Correct 453 ms 22388 KB Output is correct
72 Correct 381 ms 17500 KB Output is correct
73 Correct 416 ms 17564 KB Output is correct
74 Correct 454 ms 16812 KB Output is correct
75 Correct 494 ms 21784 KB Output is correct
76 Correct 418 ms 16456 KB Output is correct
77 Correct 415 ms 20736 KB Output is correct
78 Correct 466 ms 23020 KB Output is correct
79 Correct 388 ms 13316 KB Output is correct
80 Correct 525 ms 17760 KB Output is correct
81 Correct 494 ms 20480 KB Output is correct
82 Correct 498 ms 21748 KB Output is correct
83 Correct 142 ms 16132 KB Output is correct
84 Correct 238 ms 21244 KB Output is correct
85 Correct 115 ms 21248 KB Output is correct
86 Correct 181 ms 16384 KB Output is correct
87 Correct 212 ms 15108 KB Output is correct
88 Correct 275 ms 20604 KB Output is correct
89 Correct 185 ms 14856 KB Output is correct
90 Correct 201 ms 22016 KB Output is correct
91 Correct 178 ms 12292 KB Output is correct
92 Correct 222 ms 16000 KB Output is correct
93 Correct 260 ms 21880 KB Output is correct
94 Correct 405 ms 18620 KB Output is correct
95 Correct 476 ms 23320 KB Output is correct
96 Correct 360 ms 24304 KB Output is correct
97 Correct 415 ms 18148 KB Output is correct
98 Correct 413 ms 18512 KB Output is correct
99 Correct 431 ms 15984 KB Output is correct
100 Correct 511 ms 23032 KB Output is correct
101 Correct 448 ms 17220 KB Output is correct
102 Correct 436 ms 21340 KB Output is correct
103 Correct 484 ms 23284 KB Output is correct
104 Correct 404 ms 15072 KB Output is correct
105 Correct 478 ms 18928 KB Output is correct
106 Correct 496 ms 22520 KB Output is correct
107 Correct 370 ms 25128 KB Output is correct
108 Correct 387 ms 17940 KB Output is correct
109 Correct 409 ms 17808 KB Output is correct
110 Correct 394 ms 18296 KB Output is correct
111 Correct 380 ms 18520 KB Output is correct
112 Correct 376 ms 17660 KB Output is correct
113 Correct 380 ms 17756 KB Output is correct
114 Correct 396 ms 17664 KB Output is correct
115 Correct 392 ms 18256 KB Output is correct
116 Correct 384 ms 18080 KB Output is correct