Submission #725607

# Submission time Handle Problem Language Result Execution time Memory
725607 2023-04-17T18:06:01 Z bitaro1337 Joker (BOI20_joker) C++14
100 / 100
343 ms 14220 KB
//BITARO BITARO BITARO
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e5 + 5;
pair<int, int> p[N];
int s[N], eu[N], ev[N],  pos[N];
stack<pair<pair<int, int>, pair<int, int>>> st;
pair<int, int> get(int u) {
    if(p[u].first == u) return p[u];
    pair<int, int> x = get(p[u].first);
    return make_pair(x.first, x.second ^ p[u].second);
}
 
int bip_all = 1;
void uni(int a, int b) {
    if(a == b) return;
    pair<int, int> A = get(a), B = get(b);
    a = A.first, b = B.first;
    int para = A.second, parb = B.second;
    if(a == b) {
        if(para == parb) {
            bip_all = 0;
        }
    } else {
        if(s[a] >= s[b]) swap(a, b);
        st.push({p[a], p[b]});
        p[a] = make_pair(b, para ^ parb ^ 1);
        s[b] += s[a];
    }
}
void rollback(int SIZE) {
    while(st.size() > SIZE) {
        pair<int, int> a = st.top().first;
        pair<int, int> b = st.top().second;
        pair<int, int> B = p[a.first];
        s[b.first] -= s[a.first];
        p[a.first].first = a.first;
        p[a.first].second = a.second;
        st.pop();
    }
}
 
void rec(int l1, int l2, int r2) {
    assert(l1 <= l2);
    int initial_state = st.size(), initial_bip = bip_all;

    int lm = l1 + l2 >> 1;
    for(int i = l1; i < lm; ++i) uni(eu[i], ev[i]);
    int rans = r2;
    if(bip_all) {
        for(int i = r2 - 1; i >= lm; --i) {
            uni(eu[i], ev[i]);
            if(!bip_all) {
                rans = i; 
                break;
            }
        }
    }

    assert(!bip_all);
    pos[lm] = rans;

    rollback(initial_state);
    bip_all = initial_bip;
    
    if(l1 <= lm - 1) {
        for(int i = r2 - 1; i >= rans; --i) uni(eu[i], ev[i]);
        rec(l1, lm - 1, rans);

        rollback(initial_state);
        bip_all = initial_bip;
    }
    
    if(lm + 1 <= l2) {
        for(int i = l1; i <= lm - (r2 == lm); ++i) uni(eu[i], ev[i]);
        rec(lm + 1, l2, r2);

        rollback(initial_state);
        bip_all = initial_bip;
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, q; cin >> n >> m >> q;
    for(int i = 0; i <= n; ++i) {
        p[i].first = i, p[i].second = 0, s[i] = 1;
    }
    for(int i = 1; i <= m; ++i) cin >> eu[i] >> ev[i], pos[i] = -1;
    for(int i = 1; i <= m; ++i) {
        uni(eu[i], ev[i]);
    }
    if(bip_all) {
        while(q--) {
            int l, r; cin >> l >> r;
            cout << "NO\n";
        }
        return 0;
    }
    rollback(0);
    bip_all = 1;
    rec(1, m, m + 1);
    for(int i = 1; i <= m; ++i) {
        assert(pos[i] != -1);
    }
    while(q--) {
        int l, r; cin >> l >> r;
        if(pos[l] > r) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:33:21: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     while(st.size() > SIZE) {
      |           ~~~~~~~~~~^~~~~~
Joker.cpp:36:24: warning: variable 'B' set but not used [-Wunused-but-set-variable]
   36 |         pair<int, int> B = p[a.first];
      |                        ^
Joker.cpp: In function 'void rec(int, int, int)':
Joker.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |     int lm = l1 + l2 >> 1;
      |              ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 3 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 3 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 160 ms 5992 KB Output is correct
4 Correct 75 ms 8908 KB Output is correct
5 Correct 177 ms 8340 KB Output is correct
6 Correct 182 ms 5472 KB Output is correct
7 Correct 205 ms 5484 KB Output is correct
8 Correct 216 ms 5012 KB Output is correct
9 Correct 234 ms 6216 KB Output is correct
10 Correct 325 ms 8544 KB Output is correct
11 Correct 205 ms 6092 KB Output is correct
12 Correct 259 ms 7952 KB Output is correct
13 Correct 193 ms 3744 KB Output is correct
14 Correct 207 ms 4868 KB Output is correct
15 Correct 275 ms 7036 KB Output is correct
16 Correct 326 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 160 ms 5992 KB Output is correct
30 Correct 75 ms 8908 KB Output is correct
31 Correct 177 ms 8340 KB Output is correct
32 Correct 182 ms 5472 KB Output is correct
33 Correct 205 ms 5484 KB Output is correct
34 Correct 216 ms 5012 KB Output is correct
35 Correct 234 ms 6216 KB Output is correct
36 Correct 325 ms 8544 KB Output is correct
37 Correct 205 ms 6092 KB Output is correct
38 Correct 259 ms 7952 KB Output is correct
39 Correct 193 ms 3744 KB Output is correct
40 Correct 207 ms 4868 KB Output is correct
41 Correct 275 ms 7036 KB Output is correct
42 Correct 326 ms 8300 KB Output is correct
43 Correct 173 ms 10372 KB Output is correct
44 Correct 82 ms 12916 KB Output is correct
45 Correct 235 ms 13260 KB Output is correct
46 Correct 200 ms 9856 KB Output is correct
47 Correct 204 ms 9880 KB Output is correct
48 Correct 250 ms 10064 KB Output is correct
49 Correct 343 ms 12568 KB Output is correct
50 Correct 205 ms 9756 KB Output is correct
51 Correct 219 ms 11512 KB Output is correct
52 Correct 256 ms 12780 KB Output is correct
53 Correct 206 ms 8012 KB Output is correct
54 Correct 243 ms 9860 KB Output is correct
55 Correct 281 ms 11520 KB Output is correct
56 Correct 303 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 3 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 3 ms 464 KB Output is correct
55 Correct 133 ms 7792 KB Output is correct
56 Correct 43 ms 10768 KB Output is correct
57 Correct 141 ms 10248 KB Output is correct
58 Correct 159 ms 7824 KB Output is correct
59 Correct 210 ms 7760 KB Output is correct
60 Correct 257 ms 9436 KB Output is correct
61 Correct 181 ms 7800 KB Output is correct
62 Correct 211 ms 9892 KB Output is correct
63 Correct 161 ms 6008 KB Output is correct
64 Correct 234 ms 8268 KB Output is correct
65 Correct 262 ms 9980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 3 ms 472 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 3 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 3 ms 464 KB Output is correct
55 Correct 160 ms 5992 KB Output is correct
56 Correct 75 ms 8908 KB Output is correct
57 Correct 177 ms 8340 KB Output is correct
58 Correct 182 ms 5472 KB Output is correct
59 Correct 205 ms 5484 KB Output is correct
60 Correct 216 ms 5012 KB Output is correct
61 Correct 234 ms 6216 KB Output is correct
62 Correct 325 ms 8544 KB Output is correct
63 Correct 205 ms 6092 KB Output is correct
64 Correct 259 ms 7952 KB Output is correct
65 Correct 193 ms 3744 KB Output is correct
66 Correct 207 ms 4868 KB Output is correct
67 Correct 275 ms 7036 KB Output is correct
68 Correct 326 ms 8300 KB Output is correct
69 Correct 173 ms 10372 KB Output is correct
70 Correct 82 ms 12916 KB Output is correct
71 Correct 235 ms 13260 KB Output is correct
72 Correct 200 ms 9856 KB Output is correct
73 Correct 204 ms 9880 KB Output is correct
74 Correct 250 ms 10064 KB Output is correct
75 Correct 343 ms 12568 KB Output is correct
76 Correct 205 ms 9756 KB Output is correct
77 Correct 219 ms 11512 KB Output is correct
78 Correct 256 ms 12780 KB Output is correct
79 Correct 206 ms 8012 KB Output is correct
80 Correct 243 ms 9860 KB Output is correct
81 Correct 281 ms 11520 KB Output is correct
82 Correct 303 ms 12756 KB Output is correct
83 Correct 133 ms 7792 KB Output is correct
84 Correct 43 ms 10768 KB Output is correct
85 Correct 141 ms 10248 KB Output is correct
86 Correct 159 ms 7824 KB Output is correct
87 Correct 210 ms 7760 KB Output is correct
88 Correct 257 ms 9436 KB Output is correct
89 Correct 181 ms 7800 KB Output is correct
90 Correct 211 ms 9892 KB Output is correct
91 Correct 161 ms 6008 KB Output is correct
92 Correct 234 ms 8268 KB Output is correct
93 Correct 262 ms 9980 KB Output is correct
94 Correct 168 ms 11020 KB Output is correct
95 Correct 257 ms 14012 KB Output is correct
96 Correct 169 ms 13516 KB Output is correct
97 Correct 192 ms 10520 KB Output is correct
98 Correct 209 ms 10456 KB Output is correct
99 Correct 224 ms 9980 KB Output is correct
100 Correct 271 ms 13520 KB Output is correct
101 Correct 191 ms 10492 KB Output is correct
102 Correct 250 ms 12160 KB Output is correct
103 Correct 276 ms 13624 KB Output is correct
104 Correct 229 ms 9376 KB Output is correct
105 Correct 272 ms 11604 KB Output is correct
106 Correct 308 ms 13212 KB Output is correct
107 Correct 136 ms 14220 KB Output is correct
108 Correct 182 ms 10956 KB Output is correct
109 Correct 171 ms 10860 KB Output is correct
110 Correct 185 ms 10860 KB Output is correct
111 Correct 170 ms 10852 KB Output is correct
112 Correct 176 ms 10876 KB Output is correct
113 Correct 165 ms 10836 KB Output is correct
114 Correct 183 ms 10860 KB Output is correct
115 Correct 165 ms 10828 KB Output is correct
116 Correct 167 ms 10848 KB Output is correct