Submission #1093493

# Submission time Handle Problem Language Result Execution time Memory
1093493 2024-09-27T01:22:36 Z duckindog Joker (BOI20_joker) C++17
100 / 100
305 ms 14516 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200'000 + 10;
int n, m, q;
struct Edge { 
  int u, v;
  friend istream& operator >> (istream& is, auto& rhs) { 
    return is >> rhs.u >> rhs.v;
  }
} edge[N];

int id[N], cnt;
bool mk[N];
vector<tuple<int, int, int, int, int, int>> undo;
int root(int u) { return id[u] < 0 ? u : root(id[u]); }
bool chk(int u) { return id[u] < 0 ? mk[u] : mk[u] ^ chk(id[u]); }
void add(int u, int v) { 
  int oU = u, oV = v;
  u = root(u); v = root(v);
  if (u == v) { 
    undo.emplace_back(0, 0, 0, 0, 0, cnt);
    cnt += chk(oU) == chk(oV);
    return;
  }
  
  if (id[u] > id[v]) swap(u, v);
  undo.emplace_back(u, id[u], v, id[v], mk[v], cnt);

  mk[v] ^= (chk(oU) == chk(oV));
  id[u] += id[v];
  id[v] = u;
}
void rollBack() { 
  auto [u, idU, v, idV, mkV, pCnt] = undo.back(); undo.pop_back();
  id[u] = idU;
  id[v] = idV;
  mk[v] = mkV;
  cnt = pCnt;
}

int f[N];
void dnc(int l, int r, int lt, int rt) { 
  if (l > r) return;
  int mid = (l + r) >> 1;
  auto& ret = f[mid];

  for (int i = l; i < mid; ++i) add(edge[i].u, edge[i].v);
  for (int i = rt; i >= max(mid + 1, lt); --i) add(edge[i].u, edge[i].v);

  for (int i = max(mid + 1, lt); i <= rt; ++i) { 
    if (cnt) ret = i - 1;
    rollBack();
  } if (cnt) ret = rt;
  
  int nxtR = (!ret ? max(mid + 1, lt) : ret),
      nxtL = (!ret ? mid : ret);

  add(edge[mid].u, edge[mid].v);
  dnc(mid + 1, r, nxtR, rt);
  for (int i = mid; i >= l; --i) rollBack();

  for (int i = rt; i > nxtL; --i) add(edge[i].u, edge[i].v);
  dnc(l, mid - 1, lt, nxtL);
  for (int i = rt; i > nxtL; --i) rollBack();
}

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> m >> q;
  for (int i = 1; i <= m; ++i) cin >> edge[i];

  memset(id, -1, sizeof id);
  dnc(1, m, 1, m);

  while (q--) { 
    int l, r; cin >> l >> r;
    cout << (r <= f[l] ? "YES" : "NO") << "\n";
  }
}

Compilation message

Joker.cpp:9:45: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
    9 |   friend istream& operator >> (istream& is, auto& rhs) {
      |                                             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1128 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1128 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1248 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 2 ms 1368 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 2 ms 1296 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 2 ms 1372 KB Output is correct
40 Correct 2 ms 1372 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 2 ms 1372 KB Output is correct
43 Correct 2 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 2 ms 1412 KB Output is correct
46 Correct 2 ms 1372 KB Output is correct
47 Correct 2 ms 1372 KB Output is correct
48 Correct 2 ms 1388 KB Output is correct
49 Correct 2 ms 1372 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 2 ms 1368 KB Output is correct
52 Correct 2 ms 1624 KB Output is correct
53 Correct 3 ms 1372 KB Output is correct
54 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 140 ms 9208 KB Output is correct
4 Correct 152 ms 9152 KB Output is correct
5 Correct 178 ms 9220 KB Output is correct
6 Correct 191 ms 9096 KB Output is correct
7 Correct 237 ms 9004 KB Output is correct
8 Correct 237 ms 9152 KB Output is correct
9 Correct 248 ms 9160 KB Output is correct
10 Correct 262 ms 9144 KB Output is correct
11 Correct 198 ms 9160 KB Output is correct
12 Correct 212 ms 9152 KB Output is correct
13 Correct 228 ms 8908 KB Output is correct
14 Correct 228 ms 9156 KB Output is correct
15 Correct 269 ms 9156 KB Output is correct
16 Correct 267 ms 9148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1128 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 140 ms 9208 KB Output is correct
30 Correct 152 ms 9152 KB Output is correct
31 Correct 178 ms 9220 KB Output is correct
32 Correct 191 ms 9096 KB Output is correct
33 Correct 237 ms 9004 KB Output is correct
34 Correct 237 ms 9152 KB Output is correct
35 Correct 248 ms 9160 KB Output is correct
36 Correct 262 ms 9144 KB Output is correct
37 Correct 198 ms 9160 KB Output is correct
38 Correct 212 ms 9152 KB Output is correct
39 Correct 228 ms 8908 KB Output is correct
40 Correct 228 ms 9156 KB Output is correct
41 Correct 269 ms 9156 KB Output is correct
42 Correct 267 ms 9148 KB Output is correct
43 Correct 150 ms 13196 KB Output is correct
44 Correct 161 ms 12288 KB Output is correct
45 Correct 202 ms 13396 KB Output is correct
46 Correct 201 ms 13444 KB Output is correct
47 Correct 221 ms 13420 KB Output is correct
48 Correct 256 ms 12980 KB Output is correct
49 Correct 289 ms 13340 KB Output is correct
50 Correct 198 ms 13344 KB Output is correct
51 Correct 203 ms 13340 KB Output is correct
52 Correct 203 ms 13488 KB Output is correct
53 Correct 230 ms 12980 KB Output is correct
54 Correct 255 ms 13236 KB Output is correct
55 Correct 256 ms 13492 KB Output is correct
56 Correct 286 ms 13488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1128 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1248 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 2 ms 1368 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 2 ms 1296 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 2 ms 1372 KB Output is correct
40 Correct 2 ms 1372 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 2 ms 1372 KB Output is correct
43 Correct 2 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 2 ms 1412 KB Output is correct
46 Correct 2 ms 1372 KB Output is correct
47 Correct 2 ms 1372 KB Output is correct
48 Correct 2 ms 1388 KB Output is correct
49 Correct 2 ms 1372 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 2 ms 1368 KB Output is correct
52 Correct 2 ms 1624 KB Output is correct
53 Correct 3 ms 1372 KB Output is correct
54 Correct 2 ms 1372 KB Output is correct
55 Correct 120 ms 11464 KB Output is correct
56 Correct 122 ms 11716 KB Output is correct
57 Correct 148 ms 11748 KB Output is correct
58 Correct 195 ms 11452 KB Output is correct
59 Correct 226 ms 11464 KB Output is correct
60 Correct 244 ms 11716 KB Output is correct
61 Correct 182 ms 11288 KB Output is correct
62 Correct 190 ms 11716 KB Output is correct
63 Correct 198 ms 11200 KB Output is correct
64 Correct 230 ms 11460 KB Output is correct
65 Correct 245 ms 11720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1240 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1112 KB Output is correct
14 Correct 1 ms 1112 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1112 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1116 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 1 ms 1116 KB Output is correct
27 Correct 1 ms 1128 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 2 ms 1248 KB Output is correct
30 Correct 3 ms 1372 KB Output is correct
31 Correct 2 ms 1368 KB Output is correct
32 Correct 2 ms 1372 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 2 ms 1296 KB Output is correct
36 Correct 2 ms 1372 KB Output is correct
37 Correct 2 ms 1372 KB Output is correct
38 Correct 2 ms 1372 KB Output is correct
39 Correct 2 ms 1372 KB Output is correct
40 Correct 2 ms 1372 KB Output is correct
41 Correct 2 ms 1372 KB Output is correct
42 Correct 2 ms 1372 KB Output is correct
43 Correct 2 ms 1372 KB Output is correct
44 Correct 2 ms 1372 KB Output is correct
45 Correct 2 ms 1412 KB Output is correct
46 Correct 2 ms 1372 KB Output is correct
47 Correct 2 ms 1372 KB Output is correct
48 Correct 2 ms 1388 KB Output is correct
49 Correct 2 ms 1372 KB Output is correct
50 Correct 2 ms 1372 KB Output is correct
51 Correct 2 ms 1368 KB Output is correct
52 Correct 2 ms 1624 KB Output is correct
53 Correct 3 ms 1372 KB Output is correct
54 Correct 2 ms 1372 KB Output is correct
55 Correct 140 ms 9208 KB Output is correct
56 Correct 152 ms 9152 KB Output is correct
57 Correct 178 ms 9220 KB Output is correct
58 Correct 191 ms 9096 KB Output is correct
59 Correct 237 ms 9004 KB Output is correct
60 Correct 237 ms 9152 KB Output is correct
61 Correct 248 ms 9160 KB Output is correct
62 Correct 262 ms 9144 KB Output is correct
63 Correct 198 ms 9160 KB Output is correct
64 Correct 212 ms 9152 KB Output is correct
65 Correct 228 ms 8908 KB Output is correct
66 Correct 228 ms 9156 KB Output is correct
67 Correct 269 ms 9156 KB Output is correct
68 Correct 267 ms 9148 KB Output is correct
69 Correct 150 ms 13196 KB Output is correct
70 Correct 161 ms 12288 KB Output is correct
71 Correct 202 ms 13396 KB Output is correct
72 Correct 201 ms 13444 KB Output is correct
73 Correct 221 ms 13420 KB Output is correct
74 Correct 256 ms 12980 KB Output is correct
75 Correct 289 ms 13340 KB Output is correct
76 Correct 198 ms 13344 KB Output is correct
77 Correct 203 ms 13340 KB Output is correct
78 Correct 203 ms 13488 KB Output is correct
79 Correct 230 ms 12980 KB Output is correct
80 Correct 255 ms 13236 KB Output is correct
81 Correct 256 ms 13492 KB Output is correct
82 Correct 286 ms 13488 KB Output is correct
83 Correct 120 ms 11464 KB Output is correct
84 Correct 122 ms 11716 KB Output is correct
85 Correct 148 ms 11748 KB Output is correct
86 Correct 195 ms 11452 KB Output is correct
87 Correct 226 ms 11464 KB Output is correct
88 Correct 244 ms 11716 KB Output is correct
89 Correct 182 ms 11288 KB Output is correct
90 Correct 190 ms 11716 KB Output is correct
91 Correct 198 ms 11200 KB Output is correct
92 Correct 230 ms 11460 KB Output is correct
93 Correct 245 ms 11720 KB Output is correct
94 Correct 157 ms 14024 KB Output is correct
95 Correct 164 ms 14256 KB Output is correct
96 Correct 176 ms 14252 KB Output is correct
97 Correct 200 ms 14060 KB Output is correct
98 Correct 226 ms 14160 KB Output is correct
99 Correct 240 ms 14012 KB Output is correct
100 Correct 260 ms 14268 KB Output is correct
101 Correct 210 ms 14000 KB Output is correct
102 Correct 218 ms 14256 KB Output is correct
103 Correct 229 ms 14260 KB Output is correct
104 Correct 235 ms 13996 KB Output is correct
105 Correct 271 ms 14180 KB Output is correct
106 Correct 305 ms 14264 KB Output is correct
107 Correct 106 ms 14516 KB Output is correct
108 Correct 154 ms 13892 KB Output is correct
109 Correct 150 ms 13748 KB Output is correct
110 Correct 147 ms 13860 KB Output is correct
111 Correct 152 ms 13752 KB Output is correct
112 Correct 143 ms 13748 KB Output is correct
113 Correct 147 ms 13748 KB Output is correct
114 Correct 150 ms 13868 KB Output is correct
115 Correct 144 ms 13692 KB Output is correct
116 Correct 145 ms 13692 KB Output is correct