답안 #651979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651979 2022-10-21T02:00:07 Z lunchbox1 Joker (BOI20_joker) C++17
100 / 100
219 ms 14228 KB
/*
 author: lunchbox
 problem link: https://oj.uz/problem/view/BOI20_joker
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5, M = 2e5 + 5;

pair<int, int> p[N];
int s[N];

pair<int, int> find(int i) {
 if (p[i].first == i) return {i, 0};
 auto [x, u] = find(p[i].first);
 return {x, u ^ p[i].second};
}
vector<tuple<int, int, pair<int, int>>> un;
bool join(int i, int j) {
 auto [x, u] = find(i); auto [y, v] = find(j);
 if (x == y) {
  un.push_back({-1, -1, {-1, -1}});
  return u == v;
 }
 if (s[x] < s[y]) swap(x, y);
 un.push_back({x, y, p[y]});
 s[x] += s[y], p[y] = {x, 1 ^ u ^ v};
 return 0;
}
void undo() {
 auto [i, j, p_] = un.back();
 if (i != -1) s[i] -= s[j], p[j] = p_;
 un.pop_back();
}

int u[M], v[M], o[M];

void solve(int l, int r, int l_, int r_) {
 if (l > r) return;
 if (l_ == r_) {
  for (int i = l; i <= r; i++) o[i] = l_;
  return;
 }
 int m = (l + r) / 2;
 bool g = 0;
 for (int i = l; i <= m; i++) g |= join(u[i], v[i]);
 int t = r_ + 1;
 while (!g) t--, g |= join(u[t], v[t]);
 o[m] = t;
 for (int i = t; i <= r_; i++) undo();
 solve(m + 1, r, t, r_);
 for (int i = l; i <= m; i++) undo();
 for (int i = t + 1; i <= r_; i++) join(u[i], v[i]);
 solve(l, m - 1, l_, t);
 for (int i = t + 1; i <= r_; i++) undo();
}

int main() {
 ios::sync_with_stdio(false), cin.tie(NULL);
 int n, m, q; cin >> n >> m >> q;
 for (int i = 0; i < n; i++) s[i] = 1, p[i] = {i, 0};
 int g = m + 1;
 for (int i = 1; i <= m; i++) {
  cin >> u[i] >> v[i], u[i]--, v[i]--;
  if (join(u[i], v[i])) g = min(g, i);
 }
 if (g == m + 1) {
  while (q--)
   cout << "NO" << '\n';
  return 0;
 }
 for (int i = g; i <= m; i++) o[i] = m + 1;
 for (int i = 1; i <= m; i++) undo();
 int t = m;
 while (!join(u[t], v[t])) t--;
 o[0] = t;
 for (int i = t; i <= m; i++) undo();
 solve(1, g - 1, o[0], m);
 for (int i = 0; i < n; i++) s[i] = 1, p[i] = {i, 0};
 while (q--) {
  int l, r; cin >> l >> r;
  cout << (o[l - 1] > r ? "YES" : "NO") << '\n';
 }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 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 340 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 284 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 344 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 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 340 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 284 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 344 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 476 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 480 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 476 KB Output is correct
39 Correct 1 ms 472 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 484 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 476 KB Output is correct
45 Correct 2 ms 440 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 2 ms 480 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 464 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 155 ms 11736 KB Output is correct
4 Correct 76 ms 10744 KB Output is correct
5 Correct 123 ms 12836 KB Output is correct
6 Correct 129 ms 11644 KB Output is correct
7 Correct 108 ms 11752 KB Output is correct
8 Correct 152 ms 10712 KB Output is correct
9 Correct 152 ms 11196 KB Output is correct
10 Correct 213 ms 12600 KB Output is correct
11 Correct 184 ms 11672 KB Output is correct
12 Correct 214 ms 12776 KB Output is correct
13 Correct 131 ms 10552 KB Output is correct
14 Correct 149 ms 11324 KB Output is correct
15 Correct 202 ms 12196 KB Output is correct
16 Correct 199 ms 12900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 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 340 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 284 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 344 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 155 ms 11736 KB Output is correct
30 Correct 76 ms 10744 KB Output is correct
31 Correct 123 ms 12836 KB Output is correct
32 Correct 129 ms 11644 KB Output is correct
33 Correct 108 ms 11752 KB Output is correct
34 Correct 152 ms 10712 KB Output is correct
35 Correct 152 ms 11196 KB Output is correct
36 Correct 213 ms 12600 KB Output is correct
37 Correct 184 ms 11672 KB Output is correct
38 Correct 214 ms 12776 KB Output is correct
39 Correct 131 ms 10552 KB Output is correct
40 Correct 149 ms 11324 KB Output is correct
41 Correct 202 ms 12196 KB Output is correct
42 Correct 199 ms 12900 KB Output is correct
43 Correct 167 ms 12072 KB Output is correct
44 Correct 72 ms 10756 KB Output is correct
45 Correct 172 ms 13224 KB Output is correct
46 Correct 123 ms 12208 KB Output is correct
47 Correct 158 ms 11956 KB Output is correct
48 Correct 148 ms 11828 KB Output is correct
49 Correct 219 ms 13036 KB Output is correct
50 Correct 151 ms 11700 KB Output is correct
51 Correct 197 ms 12624 KB Output is correct
52 Correct 170 ms 13244 KB Output is correct
53 Correct 138 ms 10884 KB Output is correct
54 Correct 195 ms 11708 KB Output is correct
55 Correct 194 ms 12804 KB Output is correct
56 Correct 209 ms 13248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 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 340 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 284 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 344 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 476 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 480 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 476 KB Output is correct
39 Correct 1 ms 472 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 484 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 476 KB Output is correct
45 Correct 2 ms 440 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 2 ms 480 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 464 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 110 ms 9420 KB Output is correct
56 Correct 59 ms 10024 KB Output is correct
57 Correct 89 ms 10580 KB Output is correct
58 Correct 82 ms 9336 KB Output is correct
59 Correct 129 ms 9404 KB Output is correct
60 Correct 152 ms 10300 KB Output is correct
61 Correct 126 ms 9448 KB Output is correct
62 Correct 162 ms 10556 KB Output is correct
63 Correct 108 ms 8676 KB Output is correct
64 Correct 129 ms 9716 KB Output is correct
65 Correct 187 ms 10476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 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 340 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 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 284 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 344 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 476 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 480 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 2 ms 476 KB Output is correct
39 Correct 1 ms 472 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 484 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 476 KB Output is correct
45 Correct 2 ms 440 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 2 ms 480 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 464 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 155 ms 11736 KB Output is correct
56 Correct 76 ms 10744 KB Output is correct
57 Correct 123 ms 12836 KB Output is correct
58 Correct 129 ms 11644 KB Output is correct
59 Correct 108 ms 11752 KB Output is correct
60 Correct 152 ms 10712 KB Output is correct
61 Correct 152 ms 11196 KB Output is correct
62 Correct 213 ms 12600 KB Output is correct
63 Correct 184 ms 11672 KB Output is correct
64 Correct 214 ms 12776 KB Output is correct
65 Correct 131 ms 10552 KB Output is correct
66 Correct 149 ms 11324 KB Output is correct
67 Correct 202 ms 12196 KB Output is correct
68 Correct 199 ms 12900 KB Output is correct
69 Correct 167 ms 12072 KB Output is correct
70 Correct 72 ms 10756 KB Output is correct
71 Correct 172 ms 13224 KB Output is correct
72 Correct 123 ms 12208 KB Output is correct
73 Correct 158 ms 11956 KB Output is correct
74 Correct 148 ms 11828 KB Output is correct
75 Correct 219 ms 13036 KB Output is correct
76 Correct 151 ms 11700 KB Output is correct
77 Correct 197 ms 12624 KB Output is correct
78 Correct 170 ms 13244 KB Output is correct
79 Correct 138 ms 10884 KB Output is correct
80 Correct 195 ms 11708 KB Output is correct
81 Correct 194 ms 12804 KB Output is correct
82 Correct 209 ms 13248 KB Output is correct
83 Correct 110 ms 9420 KB Output is correct
84 Correct 59 ms 10024 KB Output is correct
85 Correct 89 ms 10580 KB Output is correct
86 Correct 82 ms 9336 KB Output is correct
87 Correct 129 ms 9404 KB Output is correct
88 Correct 152 ms 10300 KB Output is correct
89 Correct 126 ms 9448 KB Output is correct
90 Correct 162 ms 10556 KB Output is correct
91 Correct 108 ms 8676 KB Output is correct
92 Correct 129 ms 9716 KB Output is correct
93 Correct 187 ms 10476 KB Output is correct
94 Correct 180 ms 12744 KB Output is correct
95 Correct 213 ms 13912 KB Output is correct
96 Correct 143 ms 13888 KB Output is correct
97 Correct 116 ms 12700 KB Output is correct
98 Correct 120 ms 12724 KB Output is correct
99 Correct 156 ms 12224 KB Output is correct
100 Correct 171 ms 14028 KB Output is correct
101 Correct 158 ms 12504 KB Output is correct
102 Correct 190 ms 13524 KB Output is correct
103 Correct 193 ms 14028 KB Output is correct
104 Correct 140 ms 11900 KB Output is correct
105 Correct 180 ms 13064 KB Output is correct
106 Correct 210 ms 13864 KB Output is correct
107 Correct 99 ms 14228 KB Output is correct
108 Correct 166 ms 12428 KB Output is correct
109 Correct 163 ms 12456 KB Output is correct
110 Correct 159 ms 12456 KB Output is correct
111 Correct 165 ms 12480 KB Output is correct
112 Correct 161 ms 12472 KB Output is correct
113 Correct 163 ms 12468 KB Output is correct
114 Correct 164 ms 12544 KB Output is correct
115 Correct 156 ms 12432 KB Output is correct
116 Correct 153 ms 12516 KB Output is correct