답안 #766169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766169 2023-06-25T10:58:15 Z keta_tsimakuridze Joker (BOI20_joker) C++14
100 / 100
179 ms 11068 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(1, opt); i < R; i++) merge(e[i].f, e[i].s);
    if(l < mid) solve(l, mid - 1, L, opt);
    rollback(I);

}
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    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(int)':
Joker.cpp:31:21: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and '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(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5048 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4972 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5048 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4972 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 7 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 ms 5096 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5204 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 104 ms 9720 KB Output is correct
4 Correct 131 ms 10848 KB Output is correct
5 Correct 91 ms 10612 KB Output is correct
6 Correct 118 ms 9892 KB Output is correct
7 Correct 115 ms 9648 KB Output is correct
8 Correct 120 ms 9204 KB Output is correct
9 Correct 133 ms 9792 KB Output is correct
10 Correct 169 ms 11036 KB Output is correct
11 Correct 126 ms 9672 KB Output is correct
12 Correct 142 ms 10704 KB Output is correct
13 Correct 127 ms 8440 KB Output is correct
14 Correct 130 ms 9192 KB Output is correct
15 Correct 165 ms 10164 KB Output is correct
16 Correct 166 ms 10876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5048 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4972 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 104 ms 9720 KB Output is correct
30 Correct 131 ms 10848 KB Output is correct
31 Correct 91 ms 10612 KB Output is correct
32 Correct 118 ms 9892 KB Output is correct
33 Correct 115 ms 9648 KB Output is correct
34 Correct 120 ms 9204 KB Output is correct
35 Correct 133 ms 9792 KB Output is correct
36 Correct 169 ms 11036 KB Output is correct
37 Correct 126 ms 9672 KB Output is correct
38 Correct 142 ms 10704 KB Output is correct
39 Correct 127 ms 8440 KB Output is correct
40 Correct 130 ms 9192 KB Output is correct
41 Correct 165 ms 10164 KB Output is correct
42 Correct 166 ms 10876 KB Output is correct
43 Correct 106 ms 9700 KB Output is correct
44 Correct 135 ms 10824 KB Output is correct
45 Correct 142 ms 10792 KB Output is correct
46 Correct 112 ms 9672 KB Output is correct
47 Correct 114 ms 9700 KB Output is correct
48 Correct 146 ms 9852 KB Output is correct
49 Correct 173 ms 11060 KB Output is correct
50 Correct 125 ms 9436 KB Output is correct
51 Correct 146 ms 10372 KB Output is correct
52 Correct 145 ms 10852 KB Output is correct
53 Correct 129 ms 8532 KB Output is correct
54 Correct 145 ms 9376 KB Output is correct
55 Correct 165 ms 10248 KB Output is correct
56 Correct 170 ms 10916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5048 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4972 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 7 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 ms 5096 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5204 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5100 KB Output is correct
55 Correct 80 ms 9040 KB Output is correct
56 Correct 108 ms 10512 KB Output is correct
57 Correct 69 ms 10076 KB Output is correct
58 Correct 89 ms 9132 KB Output is correct
59 Correct 119 ms 9120 KB Output is correct
60 Correct 147 ms 9756 KB Output is correct
61 Correct 115 ms 9088 KB Output is correct
62 Correct 122 ms 10056 KB Output is correct
63 Correct 96 ms 8128 KB Output is correct
64 Correct 132 ms 9252 KB Output is correct
65 Correct 150 ms 10040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 4996 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Correct 2 ms 5048 KB Output is correct
9 Correct 2 ms 4948 KB Output is correct
10 Correct 2 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 2 ms 4948 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 2 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 2 ms 4948 KB Output is correct
20 Correct 2 ms 4948 KB Output is correct
21 Correct 2 ms 4948 KB Output is correct
22 Correct 2 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 2 ms 4972 KB Output is correct
25 Correct 2 ms 4948 KB Output is correct
26 Correct 2 ms 4948 KB Output is correct
27 Correct 2 ms 4948 KB Output is correct
28 Correct 2 ms 4948 KB Output is correct
29 Correct 3 ms 5076 KB Output is correct
30 Correct 3 ms 5076 KB Output is correct
31 Correct 3 ms 5076 KB Output is correct
32 Correct 3 ms 5076 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 3 ms 5076 KB Output is correct
36 Correct 3 ms 5076 KB Output is correct
37 Correct 3 ms 5076 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 5076 KB Output is correct
40 Correct 3 ms 5076 KB Output is correct
41 Correct 3 ms 5076 KB Output is correct
42 Correct 3 ms 5076 KB Output is correct
43 Correct 7 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 3 ms 5076 KB Output is correct
46 Correct 3 ms 5076 KB Output is correct
47 Correct 3 ms 5076 KB Output is correct
48 Correct 3 ms 5076 KB Output is correct
49 Correct 4 ms 5096 KB Output is correct
50 Correct 3 ms 5076 KB Output is correct
51 Correct 3 ms 5076 KB Output is correct
52 Correct 4 ms 5204 KB Output is correct
53 Correct 3 ms 5076 KB Output is correct
54 Correct 3 ms 5100 KB Output is correct
55 Correct 104 ms 9720 KB Output is correct
56 Correct 131 ms 10848 KB Output is correct
57 Correct 91 ms 10612 KB Output is correct
58 Correct 118 ms 9892 KB Output is correct
59 Correct 115 ms 9648 KB Output is correct
60 Correct 120 ms 9204 KB Output is correct
61 Correct 133 ms 9792 KB Output is correct
62 Correct 169 ms 11036 KB Output is correct
63 Correct 126 ms 9672 KB Output is correct
64 Correct 142 ms 10704 KB Output is correct
65 Correct 127 ms 8440 KB Output is correct
66 Correct 130 ms 9192 KB Output is correct
67 Correct 165 ms 10164 KB Output is correct
68 Correct 166 ms 10876 KB Output is correct
69 Correct 106 ms 9700 KB Output is correct
70 Correct 135 ms 10824 KB Output is correct
71 Correct 142 ms 10792 KB Output is correct
72 Correct 112 ms 9672 KB Output is correct
73 Correct 114 ms 9700 KB Output is correct
74 Correct 146 ms 9852 KB Output is correct
75 Correct 173 ms 11060 KB Output is correct
76 Correct 125 ms 9436 KB Output is correct
77 Correct 146 ms 10372 KB Output is correct
78 Correct 145 ms 10852 KB Output is correct
79 Correct 129 ms 8532 KB Output is correct
80 Correct 145 ms 9376 KB Output is correct
81 Correct 165 ms 10248 KB Output is correct
82 Correct 170 ms 10916 KB Output is correct
83 Correct 80 ms 9040 KB Output is correct
84 Correct 108 ms 10512 KB Output is correct
85 Correct 69 ms 10076 KB Output is correct
86 Correct 89 ms 9132 KB Output is correct
87 Correct 119 ms 9120 KB Output is correct
88 Correct 147 ms 9756 KB Output is correct
89 Correct 115 ms 9088 KB Output is correct
90 Correct 122 ms 10056 KB Output is correct
91 Correct 96 ms 8128 KB Output is correct
92 Correct 132 ms 9252 KB Output is correct
93 Correct 150 ms 10040 KB Output is correct
94 Correct 117 ms 9868 KB Output is correct
95 Correct 131 ms 10844 KB Output is correct
96 Correct 110 ms 10696 KB Output is correct
97 Correct 118 ms 9776 KB Output is correct
98 Correct 121 ms 9788 KB Output is correct
99 Correct 136 ms 9156 KB Output is correct
100 Correct 156 ms 11068 KB Output is correct
101 Correct 127 ms 9472 KB Output is correct
102 Correct 151 ms 10392 KB Output is correct
103 Correct 158 ms 10908 KB Output is correct
104 Correct 135 ms 8852 KB Output is correct
105 Correct 160 ms 10092 KB Output is correct
106 Correct 179 ms 10812 KB Output is correct
107 Correct 77 ms 10784 KB Output is correct
108 Correct 106 ms 9696 KB Output is correct
109 Correct 108 ms 9636 KB Output is correct
110 Correct 108 ms 9704 KB Output is correct
111 Correct 108 ms 9644 KB Output is correct
112 Correct 119 ms 9708 KB Output is correct
113 Correct 108 ms 9720 KB Output is correct
114 Correct 116 ms 9800 KB Output is correct
115 Correct 108 ms 9740 KB Output is correct
116 Correct 111 ms 9724 KB Output is correct