Submission #766166

# Submission time Handle Problem Language Result Execution time Memory
766166 2023-06-25T10:57:19 Z keta_tsimakuridze Joker (BOI20_joker) C++14
100 / 100
500 ms 20996 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t, p[N], up[N], sz[N], ans[N], odd = 0;
vector<int> V[N];
pair<int,int> e[N];
stack<int> st;
pair<int,int> find(int u) {
    if(p[u] == u) return {u, 0};
    pii P = find(p[u]);
    P.s ^= up[u];
    return P;
}
void merge(int u, int v) {
    pii U = find(u), V = find(v);
    if(sz[U.f] < sz[V.f]) swap(U, V);
    if(U.f != V.f) {
        st.push(V.f);
        p[V.f] = U.f;
        sz[U.f] += sz[V.f];
        up[V.f] = (U.s != V.s ? 0 : 1);
        return;
    }
    if(U.s == V.s) ++odd, st.push(-1);
}
void rollback(int X) {
    while(st.size() > X) {
        int x = st.top();
        st.pop();
        if(x == -1) --odd;
        else sz[p[x]] -= sz[x], p[x] = x, up[x] = 0;
    }
}
void solve(int l, int r, int L, int R) {
    int mid = (l + r) / 2;
    int I = st.size();
    for(int i = l; i <= mid; i++) {
        merge(e[i].f, e[i].s);
    }
    int I2 = st.size();
    int opt = R;
    while(opt && !odd) {
        --opt;
        if(!opt) break;
        merge(e[opt].f, e[opt].s);

    }
    ans[mid] = opt;
    rollback(I2);
    if(mid + 1 <= r) solve(mid + 1, r, opt, R);

    rollback(I);
    for(int i = max(1ll, opt); i < R; i++) merge(e[i].f, e[i].s);
    if(l < mid) solve(l, mid - 1, L, opt);
    rollback(I);

}
main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;

    for(int i = 1; i <= m; i++) cin >> e[i].f >> e[i].s;

    e[0] = {0, 1};
    solve(0, m, 0, m + 1);
//    for(int i = 1; i <= m; i++) cout << ans[i] << " "; cout << endl;
    for(int i = 1; i <= q; i++) {
        int l, r;
        cin >> l >> r;
        cout << (ans[l - 1] > r ? "YES\n" : "NO\n");
    }
 }

Compilation message

Joker.cpp: In function 'void rollback(long long int)':
Joker.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::stack<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   31 |     while(st.size() > X) {
      |           ~~~~~~~~~~^~~
Joker.cpp: At global scope:
Joker.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4960 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4960 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4924 KB Output is correct
29 Correct 6 ms 5016 KB Output is correct
30 Correct 6 ms 5076 KB Output is correct
31 Correct 6 ms 5076 KB Output is correct
32 Correct 6 ms 5156 KB Output is correct
33 Correct 9 ms 5076 KB Output is correct
34 Correct 6 ms 5076 KB Output is correct
35 Correct 6 ms 5148 KB Output is correct
36 Correct 6 ms 5136 KB Output is correct
37 Correct 7 ms 5076 KB Output is correct
38 Correct 6 ms 5156 KB Output is correct
39 Correct 6 ms 5076 KB Output is correct
40 Correct 6 ms 5092 KB Output is correct
41 Correct 6 ms 5152 KB Output is correct
42 Correct 6 ms 5148 KB Output is correct
43 Correct 6 ms 5076 KB Output is correct
44 Correct 6 ms 5152 KB Output is correct
45 Correct 9 ms 5076 KB Output is correct
46 Correct 8 ms 5076 KB Output is correct
47 Correct 6 ms 5076 KB Output is correct
48 Correct 6 ms 5148 KB Output is correct
49 Correct 6 ms 5076 KB Output is correct
50 Correct 6 ms 5108 KB Output is correct
51 Correct 6 ms 5076 KB Output is correct
52 Correct 9 ms 5076 KB Output is correct
53 Correct 6 ms 5068 KB Output is correct
54 Correct 7 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 417 ms 13660 KB Output is correct
4 Correct 423 ms 15956 KB Output is correct
5 Correct 389 ms 15572 KB Output is correct
6 Correct 414 ms 13676 KB Output is correct
7 Correct 416 ms 13660 KB Output is correct
8 Correct 406 ms 12452 KB Output is correct
9 Correct 433 ms 13796 KB Output is correct
10 Correct 487 ms 16160 KB Output is correct
11 Correct 424 ms 13728 KB Output is correct
12 Correct 456 ms 15556 KB Output is correct
13 Correct 419 ms 11324 KB Output is correct
14 Correct 428 ms 12316 KB Output is correct
15 Correct 459 ms 14588 KB Output is correct
16 Correct 470 ms 16020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4960 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4924 KB Output is correct
29 Correct 417 ms 13660 KB Output is correct
30 Correct 423 ms 15956 KB Output is correct
31 Correct 389 ms 15572 KB Output is correct
32 Correct 414 ms 13676 KB Output is correct
33 Correct 416 ms 13660 KB Output is correct
34 Correct 406 ms 12452 KB Output is correct
35 Correct 433 ms 13796 KB Output is correct
36 Correct 487 ms 16160 KB Output is correct
37 Correct 424 ms 13728 KB Output is correct
38 Correct 456 ms 15556 KB Output is correct
39 Correct 419 ms 11324 KB Output is correct
40 Correct 428 ms 12316 KB Output is correct
41 Correct 459 ms 14588 KB Output is correct
42 Correct 470 ms 16020 KB Output is correct
43 Correct 407 ms 18000 KB Output is correct
44 Correct 425 ms 20048 KB Output is correct
45 Correct 456 ms 20348 KB Output is correct
46 Correct 412 ms 18032 KB Output is correct
47 Correct 430 ms 17996 KB Output is correct
48 Correct 446 ms 17644 KB Output is correct
49 Correct 475 ms 20392 KB Output is correct
50 Correct 430 ms 17432 KB Output is correct
51 Correct 446 ms 18976 KB Output is correct
52 Correct 451 ms 20412 KB Output is correct
53 Correct 423 ms 15412 KB Output is correct
54 Correct 462 ms 17448 KB Output is correct
55 Correct 489 ms 19028 KB Output is correct
56 Correct 478 ms 20460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4960 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4924 KB Output is correct
29 Correct 6 ms 5016 KB Output is correct
30 Correct 6 ms 5076 KB Output is correct
31 Correct 6 ms 5076 KB Output is correct
32 Correct 6 ms 5156 KB Output is correct
33 Correct 9 ms 5076 KB Output is correct
34 Correct 6 ms 5076 KB Output is correct
35 Correct 6 ms 5148 KB Output is correct
36 Correct 6 ms 5136 KB Output is correct
37 Correct 7 ms 5076 KB Output is correct
38 Correct 6 ms 5156 KB Output is correct
39 Correct 6 ms 5076 KB Output is correct
40 Correct 6 ms 5092 KB Output is correct
41 Correct 6 ms 5152 KB Output is correct
42 Correct 6 ms 5148 KB Output is correct
43 Correct 6 ms 5076 KB Output is correct
44 Correct 6 ms 5152 KB Output is correct
45 Correct 9 ms 5076 KB Output is correct
46 Correct 8 ms 5076 KB Output is correct
47 Correct 6 ms 5076 KB Output is correct
48 Correct 6 ms 5148 KB Output is correct
49 Correct 6 ms 5076 KB Output is correct
50 Correct 6 ms 5108 KB Output is correct
51 Correct 6 ms 5076 KB Output is correct
52 Correct 9 ms 5076 KB Output is correct
53 Correct 6 ms 5068 KB Output is correct
54 Correct 7 ms 5152 KB Output is correct
55 Correct 147 ms 15508 KB Output is correct
56 Correct 164 ms 18512 KB Output is correct
57 Correct 127 ms 17432 KB Output is correct
58 Correct 158 ms 15416 KB Output is correct
59 Correct 193 ms 15388 KB Output is correct
60 Correct 214 ms 16900 KB Output is correct
61 Correct 173 ms 15388 KB Output is correct
62 Correct 193 ms 17580 KB Output is correct
63 Correct 157 ms 13372 KB Output is correct
64 Correct 195 ms 15864 KB Output is correct
65 Correct 225 ms 17460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4960 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5012 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 5012 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5008 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5008 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4924 KB Output is correct
29 Correct 6 ms 5016 KB Output is correct
30 Correct 6 ms 5076 KB Output is correct
31 Correct 6 ms 5076 KB Output is correct
32 Correct 6 ms 5156 KB Output is correct
33 Correct 9 ms 5076 KB Output is correct
34 Correct 6 ms 5076 KB Output is correct
35 Correct 6 ms 5148 KB Output is correct
36 Correct 6 ms 5136 KB Output is correct
37 Correct 7 ms 5076 KB Output is correct
38 Correct 6 ms 5156 KB Output is correct
39 Correct 6 ms 5076 KB Output is correct
40 Correct 6 ms 5092 KB Output is correct
41 Correct 6 ms 5152 KB Output is correct
42 Correct 6 ms 5148 KB Output is correct
43 Correct 6 ms 5076 KB Output is correct
44 Correct 6 ms 5152 KB Output is correct
45 Correct 9 ms 5076 KB Output is correct
46 Correct 8 ms 5076 KB Output is correct
47 Correct 6 ms 5076 KB Output is correct
48 Correct 6 ms 5148 KB Output is correct
49 Correct 6 ms 5076 KB Output is correct
50 Correct 6 ms 5108 KB Output is correct
51 Correct 6 ms 5076 KB Output is correct
52 Correct 9 ms 5076 KB Output is correct
53 Correct 6 ms 5068 KB Output is correct
54 Correct 7 ms 5152 KB Output is correct
55 Correct 417 ms 13660 KB Output is correct
56 Correct 423 ms 15956 KB Output is correct
57 Correct 389 ms 15572 KB Output is correct
58 Correct 414 ms 13676 KB Output is correct
59 Correct 416 ms 13660 KB Output is correct
60 Correct 406 ms 12452 KB Output is correct
61 Correct 433 ms 13796 KB Output is correct
62 Correct 487 ms 16160 KB Output is correct
63 Correct 424 ms 13728 KB Output is correct
64 Correct 456 ms 15556 KB Output is correct
65 Correct 419 ms 11324 KB Output is correct
66 Correct 428 ms 12316 KB Output is correct
67 Correct 459 ms 14588 KB Output is correct
68 Correct 470 ms 16020 KB Output is correct
69 Correct 407 ms 18000 KB Output is correct
70 Correct 425 ms 20048 KB Output is correct
71 Correct 456 ms 20348 KB Output is correct
72 Correct 412 ms 18032 KB Output is correct
73 Correct 430 ms 17996 KB Output is correct
74 Correct 446 ms 17644 KB Output is correct
75 Correct 475 ms 20392 KB Output is correct
76 Correct 430 ms 17432 KB Output is correct
77 Correct 446 ms 18976 KB Output is correct
78 Correct 451 ms 20412 KB Output is correct
79 Correct 423 ms 15412 KB Output is correct
80 Correct 462 ms 17448 KB Output is correct
81 Correct 489 ms 19028 KB Output is correct
82 Correct 478 ms 20460 KB Output is correct
83 Correct 147 ms 15508 KB Output is correct
84 Correct 164 ms 18512 KB Output is correct
85 Correct 127 ms 17432 KB Output is correct
86 Correct 158 ms 15416 KB Output is correct
87 Correct 193 ms 15388 KB Output is correct
88 Correct 214 ms 16900 KB Output is correct
89 Correct 173 ms 15388 KB Output is correct
90 Correct 193 ms 17580 KB Output is correct
91 Correct 157 ms 13372 KB Output is correct
92 Correct 195 ms 15864 KB Output is correct
93 Correct 225 ms 17460 KB Output is correct
94 Correct 419 ms 18720 KB Output is correct
95 Correct 452 ms 20996 KB Output is correct
96 Correct 411 ms 20008 KB Output is correct
97 Correct 449 ms 18268 KB Output is correct
98 Correct 481 ms 18304 KB Output is correct
99 Correct 447 ms 16940 KB Output is correct
100 Correct 500 ms 20712 KB Output is correct
101 Correct 451 ms 17804 KB Output is correct
102 Correct 465 ms 19192 KB Output is correct
103 Correct 481 ms 20648 KB Output is correct
104 Correct 443 ms 16368 KB Output is correct
105 Correct 482 ms 18664 KB Output is correct
106 Correct 490 ms 20152 KB Output is correct
107 Correct 393 ms 20420 KB Output is correct
108 Correct 418 ms 18240 KB Output is correct
109 Correct 418 ms 18176 KB Output is correct
110 Correct 425 ms 18180 KB Output is correct
111 Correct 420 ms 18192 KB Output is correct
112 Correct 424 ms 18424 KB Output is correct
113 Correct 425 ms 18176 KB Output is correct
114 Correct 417 ms 18160 KB Output is correct
115 Correct 429 ms 18180 KB Output is correct
116 Correct 424 ms 18180 KB Output is correct