답안 #928631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928631 2024-02-16T21:09:08 Z aykhn Joker (BOI20_joker) C++17
100 / 100
330 ms 20928 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MXN = 2e5 + 5;

int n, m;
array<int, 2> ed[MXN];
stack<pair<int*, int>> st;
int par[MXN], sz[MXN], col[MXN], ans[MXN];
int bip = 1;

void make(int &x, int y)
{
    st.push({&x, x});
    x = y;
}
void undo(int c)
{
    while (st.size() > c)
    {
        pair<int*, int> x = st.top();
        *x.first = x.second;
        st.pop();
    }
}
pair<int, int> getpar(int x)
{
    if (x == par[x]) return {x, 0};
    pair<int, int> p = getpar(par[x]);
    return {p.first, p.second ^ col[x]};
}
void merge(int x, int y)
{
    pair<int, int> x1 = getpar(x), y1 = getpar(y);
    if (x1.first == y1.first) 
    {
        if (x1.second == y1.second) make(bip, 0);
        return;
    }
    if (sz[x1.first] < sz[y1.first]) swap(x1, y1);
    make(sz[x1.first], sz[x1.first] + sz[y1.first]);
    make(par[y1.first], x1.first);
    make(col[y1.first], y1.second ^ x1.second ^ 1);
}
void solve(int l, int r, int optl, int optr)
{
    if (l > r) return;
    int mid = (l + r) >> 1;
    int prevsz = st.size();
    for (int i = l; i < mid; i++) 
    {
        merge(ed[i][0], ed[i][1]);
    }
    for (int i = optr; i >= optl; i--)
    {
        merge(ed[i][0], ed[i][1]);
        if (!bip) 
        {
            ans[mid] = i;
            break;
        }
    }
    undo(prevsz);
    if (l == r) return;
    for (int i = ans[mid] + 1; i <= optr; i++)
    {
        merge(ed[i][0], ed[i][1]);
    }
    solve(l, mid - 1, optl, ans[mid]);
    undo(prevsz);
    for (int i = l; i <= mid; i++)
    {
        merge(ed[i][0], ed[i][1]);
    }
    solve(mid + 1, r, ans[mid], optr);
    undo(prevsz);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int q;
    cin >> n >> m >> q;
    for (int i = 0; i <= n; i++) par[i] = i, sz[i] = 1;
    for (int i = 1; i <= m; i++)
    {
        cin >> ed[i][0] >> ed[i][1];
    }
    ed[m + 1] = {0, 1};
    solve(1, m, 1, m + 1);
    while (q--)
    {
        int l, r;
        cin >> l >> r;
        if (ans[l] > r) cout << "YES\n";
        else cout << "NO\n";
    }
}

Compilation message

Joker.cpp: In function 'void undo(int)':
Joker.cpp:21:22: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int*, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |     while (st.size() > c)
      |            ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4560 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4560 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4532 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 3 ms 4700 KB Output is correct
35 Correct 3 ms 4700 KB Output is correct
36 Correct 2 ms 4660 KB Output is correct
37 Correct 3 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4584 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4440 KB Output is correct
54 Correct 3 ms 4696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 215 ms 16224 KB Output is correct
4 Correct 164 ms 19192 KB Output is correct
5 Correct 193 ms 18936 KB Output is correct
6 Correct 203 ms 15472 KB Output is correct
7 Correct 202 ms 15312 KB Output is correct
8 Correct 194 ms 12776 KB Output is correct
9 Correct 226 ms 14752 KB Output is correct
10 Correct 295 ms 17820 KB Output is correct
11 Correct 219 ms 15036 KB Output is correct
12 Correct 258 ms 17784 KB Output is correct
13 Correct 172 ms 11344 KB Output is correct
14 Correct 194 ms 13292 KB Output is correct
15 Correct 280 ms 16560 KB Output is correct
16 Correct 306 ms 18408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4560 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4532 KB Output is correct
29 Correct 215 ms 16224 KB Output is correct
30 Correct 164 ms 19192 KB Output is correct
31 Correct 193 ms 18936 KB Output is correct
32 Correct 203 ms 15472 KB Output is correct
33 Correct 202 ms 15312 KB Output is correct
34 Correct 194 ms 12776 KB Output is correct
35 Correct 226 ms 14752 KB Output is correct
36 Correct 295 ms 17820 KB Output is correct
37 Correct 219 ms 15036 KB Output is correct
38 Correct 258 ms 17784 KB Output is correct
39 Correct 172 ms 11344 KB Output is correct
40 Correct 194 ms 13292 KB Output is correct
41 Correct 280 ms 16560 KB Output is correct
42 Correct 306 ms 18408 KB Output is correct
43 Correct 209 ms 16408 KB Output is correct
44 Correct 158 ms 19432 KB Output is correct
45 Correct 285 ms 20160 KB Output is correct
46 Correct 200 ms 15716 KB Output is correct
47 Correct 200 ms 15736 KB Output is correct
48 Correct 241 ms 15136 KB Output is correct
49 Correct 322 ms 18296 KB Output is correct
50 Correct 203 ms 14684 KB Output is correct
51 Correct 234 ms 17116 KB Output is correct
52 Correct 271 ms 18688 KB Output is correct
53 Correct 179 ms 11520 KB Output is correct
54 Correct 230 ms 14532 KB Output is correct
55 Correct 281 ms 16968 KB Output is correct
56 Correct 301 ms 18616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4560 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4532 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 3 ms 4700 KB Output is correct
35 Correct 3 ms 4700 KB Output is correct
36 Correct 2 ms 4660 KB Output is correct
37 Correct 3 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4584 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4440 KB Output is correct
54 Correct 3 ms 4696 KB Output is correct
55 Correct 190 ms 13948 KB Output is correct
56 Correct 132 ms 17376 KB Output is correct
57 Correct 161 ms 16672 KB Output is correct
58 Correct 176 ms 13084 KB Output is correct
59 Correct 215 ms 12984 KB Output is correct
60 Correct 270 ms 15028 KB Output is correct
61 Correct 206 ms 12812 KB Output is correct
62 Correct 225 ms 15692 KB Output is correct
63 Correct 152 ms 9968 KB Output is correct
64 Correct 245 ms 13836 KB Output is correct
65 Correct 276 ms 15572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4560 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4532 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 3 ms 4700 KB Output is correct
35 Correct 3 ms 4700 KB Output is correct
36 Correct 2 ms 4660 KB Output is correct
37 Correct 3 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 2 ms 4700 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4584 KB Output is correct
44 Correct 2 ms 4444 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4700 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4440 KB Output is correct
54 Correct 3 ms 4696 KB Output is correct
55 Correct 215 ms 16224 KB Output is correct
56 Correct 164 ms 19192 KB Output is correct
57 Correct 193 ms 18936 KB Output is correct
58 Correct 203 ms 15472 KB Output is correct
59 Correct 202 ms 15312 KB Output is correct
60 Correct 194 ms 12776 KB Output is correct
61 Correct 226 ms 14752 KB Output is correct
62 Correct 295 ms 17820 KB Output is correct
63 Correct 219 ms 15036 KB Output is correct
64 Correct 258 ms 17784 KB Output is correct
65 Correct 172 ms 11344 KB Output is correct
66 Correct 194 ms 13292 KB Output is correct
67 Correct 280 ms 16560 KB Output is correct
68 Correct 306 ms 18408 KB Output is correct
69 Correct 209 ms 16408 KB Output is correct
70 Correct 158 ms 19432 KB Output is correct
71 Correct 285 ms 20160 KB Output is correct
72 Correct 200 ms 15716 KB Output is correct
73 Correct 200 ms 15736 KB Output is correct
74 Correct 241 ms 15136 KB Output is correct
75 Correct 322 ms 18296 KB Output is correct
76 Correct 203 ms 14684 KB Output is correct
77 Correct 234 ms 17116 KB Output is correct
78 Correct 271 ms 18688 KB Output is correct
79 Correct 179 ms 11520 KB Output is correct
80 Correct 230 ms 14532 KB Output is correct
81 Correct 281 ms 16968 KB Output is correct
82 Correct 301 ms 18616 KB Output is correct
83 Correct 190 ms 13948 KB Output is correct
84 Correct 132 ms 17376 KB Output is correct
85 Correct 161 ms 16672 KB Output is correct
86 Correct 176 ms 13084 KB Output is correct
87 Correct 215 ms 12984 KB Output is correct
88 Correct 270 ms 15028 KB Output is correct
89 Correct 206 ms 12812 KB Output is correct
90 Correct 225 ms 15692 KB Output is correct
91 Correct 152 ms 9968 KB Output is correct
92 Correct 245 ms 13836 KB Output is correct
93 Correct 276 ms 15572 KB Output is correct
94 Correct 254 ms 17176 KB Output is correct
95 Correct 284 ms 20548 KB Output is correct
96 Correct 229 ms 19964 KB Output is correct
97 Correct 206 ms 16532 KB Output is correct
98 Correct 235 ms 16540 KB Output is correct
99 Correct 206 ms 14500 KB Output is correct
100 Correct 315 ms 19528 KB Output is correct
101 Correct 205 ms 15448 KB Output is correct
102 Correct 281 ms 17692 KB Output is correct
103 Correct 289 ms 19436 KB Output is correct
104 Correct 195 ms 13656 KB Output is correct
105 Correct 266 ms 17080 KB Output is correct
106 Correct 330 ms 19092 KB Output is correct
107 Correct 195 ms 20928 KB Output is correct
108 Correct 211 ms 16920 KB Output is correct
109 Correct 211 ms 17164 KB Output is correct
110 Correct 212 ms 17004 KB Output is correct
111 Correct 215 ms 17060 KB Output is correct
112 Correct 215 ms 16920 KB Output is correct
113 Correct 210 ms 17068 KB Output is correct
114 Correct 221 ms 17116 KB Output is correct
115 Correct 216 ms 17136 KB Output is correct
116 Correct 228 ms 16916 KB Output is correct