Submission #906409

# Submission time Handle Problem Language Result Execution time Memory
906409 2024-01-14T08:00:20 Z Darren0724 Joker (BOI20_joker) C++17
100 / 100
512 ms 19712 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;
}

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 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 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 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7516 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7512 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 4 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7324 KB Output is correct
19 Correct 5 ms 7512 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 4 ms 7512 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7512 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7516 KB Output is correct
28 Correct 4 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 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 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7516 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7512 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 4 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7324 KB Output is correct
19 Correct 5 ms 7512 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 4 ms 7512 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7512 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7516 KB Output is correct
28 Correct 4 ms 7544 KB Output is correct
29 Correct 6 ms 7516 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7512 KB Output is correct
32 Correct 8 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7512 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 8 ms 7516 KB Output is correct
38 Correct 8 ms 7516 KB Output is correct
39 Correct 7 ms 7528 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 10 ms 7768 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 7 ms 7596 KB Output is correct
45 Correct 8 ms 7516 KB Output is correct
46 Correct 7 ms 7516 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 8 ms 7512 KB Output is correct
50 Correct 7 ms 7516 KB Output is correct
51 Correct 7 ms 7340 KB Output is correct
52 Correct 8 ms 7448 KB Output is correct
53 Correct 7 ms 7516 KB Output is correct
54 Correct 7 ms 7524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 382 ms 13832 KB Output is correct
4 Correct 488 ms 18100 KB Output is correct
5 Correct 364 ms 18692 KB Output is correct
6 Correct 402 ms 13308 KB Output is correct
7 Correct 400 ms 13068 KB Output is correct
8 Correct 414 ms 11012 KB Output is correct
9 Correct 432 ms 13828 KB Output is correct
10 Correct 482 ms 18428 KB Output is correct
11 Correct 446 ms 14512 KB Output is correct
12 Correct 437 ms 17920 KB Output is correct
13 Correct 385 ms 8960 KB Output is correct
14 Correct 416 ms 10792 KB Output is correct
15 Correct 479 ms 18940 KB Output is correct
16 Correct 480 ms 17916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 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 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7516 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7512 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 4 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7324 KB Output is correct
19 Correct 5 ms 7512 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 4 ms 7512 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7512 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7516 KB Output is correct
28 Correct 4 ms 7544 KB Output is correct
29 Correct 382 ms 13832 KB Output is correct
30 Correct 488 ms 18100 KB Output is correct
31 Correct 364 ms 18692 KB Output is correct
32 Correct 402 ms 13308 KB Output is correct
33 Correct 400 ms 13068 KB Output is correct
34 Correct 414 ms 11012 KB Output is correct
35 Correct 432 ms 13828 KB Output is correct
36 Correct 482 ms 18428 KB Output is correct
37 Correct 446 ms 14512 KB Output is correct
38 Correct 437 ms 17920 KB Output is correct
39 Correct 385 ms 8960 KB Output is correct
40 Correct 416 ms 10792 KB Output is correct
41 Correct 479 ms 18940 KB Output is correct
42 Correct 480 ms 17916 KB Output is correct
43 Correct 383 ms 13076 KB Output is correct
44 Correct 485 ms 18464 KB Output is correct
45 Correct 477 ms 19312 KB Output is correct
46 Correct 387 ms 13324 KB Output is correct
47 Correct 389 ms 13584 KB Output is correct
48 Correct 462 ms 13824 KB Output is correct
49 Correct 490 ms 18428 KB Output is correct
50 Correct 387 ms 14084 KB Output is correct
51 Correct 433 ms 18176 KB Output is correct
52 Correct 448 ms 19004 KB Output is correct
53 Correct 397 ms 9060 KB Output is correct
54 Correct 437 ms 13320 KB Output is correct
55 Correct 474 ms 19400 KB Output is correct
56 Correct 504 ms 19712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 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 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7516 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7512 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 4 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7324 KB Output is correct
19 Correct 5 ms 7512 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 4 ms 7512 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7512 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7516 KB Output is correct
28 Correct 4 ms 7544 KB Output is correct
29 Correct 6 ms 7516 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7512 KB Output is correct
32 Correct 8 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7512 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 8 ms 7516 KB Output is correct
38 Correct 8 ms 7516 KB Output is correct
39 Correct 7 ms 7528 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 10 ms 7768 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 7 ms 7596 KB Output is correct
45 Correct 8 ms 7516 KB Output is correct
46 Correct 7 ms 7516 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 8 ms 7512 KB Output is correct
50 Correct 7 ms 7516 KB Output is correct
51 Correct 7 ms 7340 KB Output is correct
52 Correct 8 ms 7448 KB Output is correct
53 Correct 7 ms 7516 KB Output is correct
54 Correct 7 ms 7524 KB Output is correct
55 Correct 139 ms 13840 KB Output is correct
56 Correct 233 ms 18832 KB Output is correct
57 Correct 116 ms 19452 KB Output is correct
58 Correct 151 ms 13312 KB Output is correct
59 Correct 201 ms 14336 KB Output is correct
60 Correct 256 ms 17920 KB Output is correct
61 Correct 187 ms 12804 KB Output is correct
62 Correct 193 ms 17756 KB Output is correct
63 Correct 149 ms 10008 KB Output is correct
64 Correct 220 ms 14344 KB Output is correct
65 Correct 252 ms 17660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 4 ms 7516 KB Output is correct
5 Correct 3 ms 7516 KB Output is correct
6 Correct 3 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 5 ms 7380 KB Output is correct
10 Correct 4 ms 7512 KB Output is correct
11 Correct 4 ms 7516 KB Output is correct
12 Correct 4 ms 7352 KB Output is correct
13 Correct 4 ms 7512 KB Output is correct
14 Correct 4 ms 7516 KB Output is correct
15 Correct 4 ms 7516 KB Output is correct
16 Correct 4 ms 7516 KB Output is correct
17 Correct 4 ms 7516 KB Output is correct
18 Correct 4 ms 7324 KB Output is correct
19 Correct 5 ms 7512 KB Output is correct
20 Correct 5 ms 7516 KB Output is correct
21 Correct 4 ms 7512 KB Output is correct
22 Correct 4 ms 7512 KB Output is correct
23 Correct 4 ms 7512 KB Output is correct
24 Correct 4 ms 7512 KB Output is correct
25 Correct 4 ms 7516 KB Output is correct
26 Correct 4 ms 7516 KB Output is correct
27 Correct 4 ms 7516 KB Output is correct
28 Correct 4 ms 7544 KB Output is correct
29 Correct 6 ms 7516 KB Output is correct
30 Correct 7 ms 7516 KB Output is correct
31 Correct 7 ms 7512 KB Output is correct
32 Correct 8 ms 7516 KB Output is correct
33 Correct 7 ms 7516 KB Output is correct
34 Correct 7 ms 7516 KB Output is correct
35 Correct 7 ms 7512 KB Output is correct
36 Correct 7 ms 7516 KB Output is correct
37 Correct 8 ms 7516 KB Output is correct
38 Correct 8 ms 7516 KB Output is correct
39 Correct 7 ms 7528 KB Output is correct
40 Correct 7 ms 7516 KB Output is correct
41 Correct 10 ms 7768 KB Output is correct
42 Correct 7 ms 7512 KB Output is correct
43 Correct 7 ms 7516 KB Output is correct
44 Correct 7 ms 7596 KB Output is correct
45 Correct 8 ms 7516 KB Output is correct
46 Correct 7 ms 7516 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 7 ms 7516 KB Output is correct
49 Correct 8 ms 7512 KB Output is correct
50 Correct 7 ms 7516 KB Output is correct
51 Correct 7 ms 7340 KB Output is correct
52 Correct 8 ms 7448 KB Output is correct
53 Correct 7 ms 7516 KB Output is correct
54 Correct 7 ms 7524 KB Output is correct
55 Correct 382 ms 13832 KB Output is correct
56 Correct 488 ms 18100 KB Output is correct
57 Correct 364 ms 18692 KB Output is correct
58 Correct 402 ms 13308 KB Output is correct
59 Correct 400 ms 13068 KB Output is correct
60 Correct 414 ms 11012 KB Output is correct
61 Correct 432 ms 13828 KB Output is correct
62 Correct 482 ms 18428 KB Output is correct
63 Correct 446 ms 14512 KB Output is correct
64 Correct 437 ms 17920 KB Output is correct
65 Correct 385 ms 8960 KB Output is correct
66 Correct 416 ms 10792 KB Output is correct
67 Correct 479 ms 18940 KB Output is correct
68 Correct 480 ms 17916 KB Output is correct
69 Correct 383 ms 13076 KB Output is correct
70 Correct 485 ms 18464 KB Output is correct
71 Correct 477 ms 19312 KB Output is correct
72 Correct 387 ms 13324 KB Output is correct
73 Correct 389 ms 13584 KB Output is correct
74 Correct 462 ms 13824 KB Output is correct
75 Correct 490 ms 18428 KB Output is correct
76 Correct 387 ms 14084 KB Output is correct
77 Correct 433 ms 18176 KB Output is correct
78 Correct 448 ms 19004 KB Output is correct
79 Correct 397 ms 9060 KB Output is correct
80 Correct 437 ms 13320 KB Output is correct
81 Correct 474 ms 19400 KB Output is correct
82 Correct 504 ms 19712 KB Output is correct
83 Correct 139 ms 13840 KB Output is correct
84 Correct 233 ms 18832 KB Output is correct
85 Correct 116 ms 19452 KB Output is correct
86 Correct 151 ms 13312 KB Output is correct
87 Correct 201 ms 14336 KB Output is correct
88 Correct 256 ms 17920 KB Output is correct
89 Correct 187 ms 12804 KB Output is correct
90 Correct 193 ms 17756 KB Output is correct
91 Correct 149 ms 10008 KB Output is correct
92 Correct 220 ms 14344 KB Output is correct
93 Correct 252 ms 17660 KB Output is correct
94 Correct 386 ms 13824 KB Output is correct
95 Correct 434 ms 18444 KB Output is correct
96 Correct 352 ms 18028 KB Output is correct
97 Correct 409 ms 14344 KB Output is correct
98 Correct 403 ms 13048 KB Output is correct
99 Correct 413 ms 11100 KB Output is correct
100 Correct 476 ms 18844 KB Output is correct
101 Correct 400 ms 14092 KB Output is correct
102 Correct 443 ms 18680 KB Output is correct
103 Correct 477 ms 18936 KB Output is correct
104 Correct 406 ms 10240 KB Output is correct
105 Correct 488 ms 14336 KB Output is correct
106 Correct 512 ms 17920 KB Output is correct
107 Correct 340 ms 18424 KB Output is correct
108 Correct 386 ms 13644 KB Output is correct
109 Correct 386 ms 13072 KB Output is correct
110 Correct 409 ms 13832 KB Output is correct
111 Correct 372 ms 13840 KB Output is correct
112 Correct 398 ms 13840 KB Output is correct
113 Correct 380 ms 13312 KB Output is correct
114 Correct 382 ms 13568 KB Output is correct
115 Correct 374 ms 12968 KB Output is correct
116 Correct 382 ms 12820 KB Output is correct