Submission #1048757

# Submission time Handle Problem Language Result Execution time Memory
1048757 2024-08-08T09:25:29 Z vjudge1 Joker (BOI20_joker) C++14
100 / 100
190 ms 19332 KB
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;
using ll=long long;
using node=tuple<int, int, pair<int, bool>, pair<int, bool>, int, int, bool, bool>;

const int N = 2e5+13;
stack<node> roll;
int n, m, q;
int x[N], y[N];
pair<int, int> par[N];
int sz[N << 1];
int res[N];
bool bipar[N+13];
int ans;
int xx, yy;

pair<int, int> f(int v){
    if(par[v].fi==v) return {v, 0};
    pair<int, int> sus=f(par[v].fi);
    sus.se^=par[v].se;
    return sus;
}

void rollback(){
    assert(roll.size());
    node tmp=roll.top();
    roll.pop();
    int u=get<0>(tmp);
    int v=get<1>(tmp);
    par[u]=get<2>(tmp);
    par[v]=get<3>(tmp);
    sz[u]=get<4>(tmp);
    sz[v]=get<5>(tmp);
    ans-=get<6>(tmp)-bipar[u];
    ans-=get<7>(tmp)-bipar[v];
    bipar[u]=get<6>(tmp);
    bipar[v]=get<7>(tmp);
}

void uni(int u, int v){
    pair<int, bool> fu=f(u);
    pair<int, bool> fv=f(v);
    bool x=fu.se;
    bool y=fv.se;
    if(sz[fu.fi] < sz[fv.fi]){
        swap(fu, fv);
        swap(u, v);
    }
    u=fu.fi;
    v=fv.fi;
    roll.push(make_tuple(u, v, par[u], par[v], sz[u], sz[v], bipar[u], bipar[v]));
    if(u==v){
        if(x==y){
        	ans+=2*bipar[u];
            bipar[u]=0;
        }
    }
    else{
        par[v]=make_pair(u, x^y^1);
        if(bipar[u] && !bipar[v]){
        	++ans;
        }
        bipar[u]&=bipar[v];
        sz[u]+=sz[v];
    }
}

void back(int x) {
    while ((int) roll.size() > x) {
        rollback();
    }
}

void solve(int l, int r, int opl, int opr) {
    if (l > r) return;
    int mid = l+r>>1;
    int tmp = roll.size();
    for (int i = l; i <= mid - 1; i++) {
        uni(x[i], y[i]);
    }
    int cringe = roll.size();
    res[mid] = -1;
    for (int i = opr; i >= max(mid, opl); i--) {
        if (ans) {
            res[mid] = i;
            break;
        }
        uni(x[i], y[i]);
    }
    if (res[mid] == -1) res[mid] = mid - 1;
    back(cringe);
    uni(x[mid], y[mid]);
    solve(mid + 1, r, res[mid], opr);
    back(tmp);
    for (int i = opr; i > res[mid]; i--) {
        uni(x[i], y[i]);
    }
    solve(l, mid - 1, opl, res[mid]);
    back(tmp);
}

void scan(){
	for(int i=0; i<=N; i++){
		par[i]={i, 0};
		sz[i]=1;
		bipar[i]=1;
	}
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++) {
        cin >> x[i] >> y[i];
    }
}

void sol(){
    solve(1, m, 1, m);
    while (q--) {
        cin >> xx >> yy;
        cout << (yy <= res[xx] ? "YES\n" : "NO\n");
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    scan();
    sol();
}

Compilation message

Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:79:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |     int mid = l+r>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4740 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4740 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4744 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4736 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4740 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4740 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4744 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4736 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4748 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4860 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4820 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 2 ms 4824 KB Output is correct
45 Correct 2 ms 4788 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 1 ms 4788 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 1 ms 4788 KB Output is correct
52 Correct 1 ms 4868 KB Output is correct
53 Correct 1 ms 4784 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 117 ms 15848 KB Output is correct
4 Correct 183 ms 16244 KB Output is correct
5 Correct 89 ms 15948 KB Output is correct
6 Correct 111 ms 15844 KB Output is correct
7 Correct 113 ms 15840 KB Output is correct
8 Correct 126 ms 15588 KB Output is correct
9 Correct 130 ms 15736 KB Output is correct
10 Correct 168 ms 15992 KB Output is correct
11 Correct 128 ms 15852 KB Output is correct
12 Correct 138 ms 16040 KB Output is correct
13 Correct 148 ms 15592 KB Output is correct
14 Correct 122 ms 15592 KB Output is correct
15 Correct 162 ms 15848 KB Output is correct
16 Correct 164 ms 15840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4740 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4740 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4744 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4736 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 117 ms 15848 KB Output is correct
30 Correct 183 ms 16244 KB Output is correct
31 Correct 89 ms 15948 KB Output is correct
32 Correct 111 ms 15844 KB Output is correct
33 Correct 113 ms 15840 KB Output is correct
34 Correct 126 ms 15588 KB Output is correct
35 Correct 130 ms 15736 KB Output is correct
36 Correct 168 ms 15992 KB Output is correct
37 Correct 128 ms 15852 KB Output is correct
38 Correct 138 ms 16040 KB Output is correct
39 Correct 148 ms 15592 KB Output is correct
40 Correct 122 ms 15592 KB Output is correct
41 Correct 162 ms 15848 KB Output is correct
42 Correct 164 ms 15840 KB Output is correct
43 Correct 116 ms 15844 KB Output is correct
44 Correct 177 ms 16756 KB Output is correct
45 Correct 162 ms 18380 KB Output is correct
46 Correct 111 ms 15844 KB Output is correct
47 Correct 109 ms 15852 KB Output is correct
48 Correct 143 ms 15840 KB Output is correct
49 Correct 168 ms 16092 KB Output is correct
50 Correct 131 ms 15764 KB Output is correct
51 Correct 141 ms 15844 KB Output is correct
52 Correct 148 ms 15840 KB Output is correct
53 Correct 144 ms 15584 KB Output is correct
54 Correct 142 ms 15840 KB Output is correct
55 Correct 160 ms 15844 KB Output is correct
56 Correct 176 ms 16052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4740 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4740 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4744 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4736 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4748 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4860 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4820 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 2 ms 4824 KB Output is correct
45 Correct 2 ms 4788 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 1 ms 4788 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 1 ms 4788 KB Output is correct
52 Correct 1 ms 4868 KB Output is correct
53 Correct 1 ms 4784 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 101 ms 15656 KB Output is correct
56 Correct 168 ms 15932 KB Output is correct
57 Correct 70 ms 15852 KB Output is correct
58 Correct 96 ms 15484 KB Output is correct
59 Correct 128 ms 15584 KB Output is correct
60 Correct 157 ms 15844 KB Output is correct
61 Correct 130 ms 15596 KB Output is correct
62 Correct 127 ms 15888 KB Output is correct
63 Correct 106 ms 15588 KB Output is correct
64 Correct 131 ms 15812 KB Output is correct
65 Correct 154 ms 15676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4740 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4740 KB Output is correct
23 Correct 1 ms 4696 KB Output is correct
24 Correct 1 ms 4744 KB Output is correct
25 Correct 1 ms 4696 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4736 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4748 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4860 KB Output is correct
35 Correct 2 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4820 KB Output is correct
40 Correct 2 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 2 ms 4824 KB Output is correct
45 Correct 2 ms 4788 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 1 ms 4788 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 1 ms 4788 KB Output is correct
52 Correct 1 ms 4868 KB Output is correct
53 Correct 1 ms 4784 KB Output is correct
54 Correct 2 ms 4700 KB Output is correct
55 Correct 117 ms 15848 KB Output is correct
56 Correct 183 ms 16244 KB Output is correct
57 Correct 89 ms 15948 KB Output is correct
58 Correct 111 ms 15844 KB Output is correct
59 Correct 113 ms 15840 KB Output is correct
60 Correct 126 ms 15588 KB Output is correct
61 Correct 130 ms 15736 KB Output is correct
62 Correct 168 ms 15992 KB Output is correct
63 Correct 128 ms 15852 KB Output is correct
64 Correct 138 ms 16040 KB Output is correct
65 Correct 148 ms 15592 KB Output is correct
66 Correct 122 ms 15592 KB Output is correct
67 Correct 162 ms 15848 KB Output is correct
68 Correct 164 ms 15840 KB Output is correct
69 Correct 116 ms 15844 KB Output is correct
70 Correct 177 ms 16756 KB Output is correct
71 Correct 162 ms 18380 KB Output is correct
72 Correct 111 ms 15844 KB Output is correct
73 Correct 109 ms 15852 KB Output is correct
74 Correct 143 ms 15840 KB Output is correct
75 Correct 168 ms 16092 KB Output is correct
76 Correct 131 ms 15764 KB Output is correct
77 Correct 141 ms 15844 KB Output is correct
78 Correct 148 ms 15840 KB Output is correct
79 Correct 144 ms 15584 KB Output is correct
80 Correct 142 ms 15840 KB Output is correct
81 Correct 160 ms 15844 KB Output is correct
82 Correct 176 ms 16052 KB Output is correct
83 Correct 101 ms 15656 KB Output is correct
84 Correct 168 ms 15932 KB Output is correct
85 Correct 70 ms 15852 KB Output is correct
86 Correct 96 ms 15484 KB Output is correct
87 Correct 128 ms 15584 KB Output is correct
88 Correct 157 ms 15844 KB Output is correct
89 Correct 130 ms 15596 KB Output is correct
90 Correct 127 ms 15888 KB Output is correct
91 Correct 106 ms 15588 KB Output is correct
92 Correct 131 ms 15812 KB Output is correct
93 Correct 154 ms 15676 KB Output is correct
94 Correct 116 ms 15852 KB Output is correct
95 Correct 146 ms 18268 KB Output is correct
96 Correct 92 ms 15844 KB Output is correct
97 Correct 118 ms 15848 KB Output is correct
98 Correct 119 ms 15840 KB Output is correct
99 Correct 156 ms 15596 KB Output is correct
100 Correct 186 ms 15928 KB Output is correct
101 Correct 134 ms 15752 KB Output is correct
102 Correct 186 ms 15984 KB Output is correct
103 Correct 190 ms 15844 KB Output is correct
104 Correct 130 ms 15584 KB Output is correct
105 Correct 173 ms 15752 KB Output is correct
106 Correct 189 ms 15936 KB Output is correct
107 Correct 94 ms 19332 KB Output is correct
108 Correct 126 ms 15852 KB Output is correct
109 Correct 137 ms 15712 KB Output is correct
110 Correct 128 ms 15784 KB Output is correct
111 Correct 123 ms 15744 KB Output is correct
112 Correct 123 ms 15748 KB Output is correct
113 Correct 121 ms 15844 KB Output is correct
114 Correct 136 ms 15828 KB Output is correct
115 Correct 116 ms 15840 KB Output is correct
116 Correct 125 ms 15848 KB Output is correct