Submission #1050727

# Submission time Handle Problem Language Result Execution time Memory
1050727 2024-08-09T13:34:35 Z duckindog Joker (BOI20_joker) C++17
100 / 100
226 ms 16052 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];
 
struct DSU { 
  int id[N], co[N], cnt;
  vector<tuple<int, int, int, int, int, int>> undo;
  bool mk[N];
  
  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]); }
  inline int color(int u) { return co[u] ^ chk(u); }
  inline 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 += color(oU) == color(oV); 
      return; 
    }

    if (id[u] > id[v]) swap(u, v);

    undo.emplace_back(u, id[u], v, id[v], mk[v], cnt);

    if (color(oU) == color(oV)) mk[v] ^= 1;
    id[u] += id[v];
    id[v] = u; 
  }
  inline 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;
  }
} T;

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) T.add(edge[i].u, edge[i].v);
  for (int i = rt; i >= max(mid + 1, lt); --i) T.add(edge[i].u, edge[i].v);
 
  for (int i = max(mid + 1, lt); i <= rt; ++i) {
    const auto& [u, v] = edge[i];
    if (T.cnt) ret = i - 1;
    T.rollBack();
  } if (T.cnt) ret = rt;
  
  int nxtr = (!ret ? max(mid, lt) : ret),
      nxtl = (!ret ? mid : ret);

  T.add(edge[mid].u, edge[mid].v);
  dnc(mid + 1, r, nxtr, rt);
  for (int i = l; i <= mid; ++i) T.rollBack();

  for (int i = rt; i > nxtl; --i) T.add(edge[i].u, edge[i].v);
  dnc(l, mid - 1, lt, nxtl);
  for (int i = rt; i > nxtl; --i) T.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(T.id, -1, sizeof T.id);
  T.cnt = 0;

  dnc(1, m, 1, m);
  while (q--) { 
    int l, r; cin >> l >> r;
    cout << (r <= f[l] ? "YES" : "NO") << "\n";
  }
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\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) {
      |                                             ^~~~
Joker.cpp: In function 'void dnc(int, int, int, int)':
Joker.cpp:52:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |   int mid = l + r >> 1;
      |             ~~^~~
Joker.cpp:59:17: warning: unused structured binding declaration [-Wunused-variable]
   59 |     const auto& [u, v] = edge[i];
      |                 ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2584 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 120 ms 11724 KB Output is correct
4 Correct 144 ms 11712 KB Output is correct
5 Correct 148 ms 14792 KB Output is correct
6 Correct 160 ms 14532 KB Output is correct
7 Correct 176 ms 14532 KB Output is correct
8 Correct 184 ms 14508 KB Output is correct
9 Correct 195 ms 14516 KB Output is correct
10 Correct 222 ms 14004 KB Output is correct
11 Correct 165 ms 14388 KB Output is correct
12 Correct 176 ms 15024 KB Output is correct
13 Correct 184 ms 14816 KB Output is correct
14 Correct 185 ms 14512 KB Output is correct
15 Correct 226 ms 15284 KB Output is correct
16 Correct 223 ms 14664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 120 ms 11724 KB Output is correct
30 Correct 144 ms 11712 KB Output is correct
31 Correct 148 ms 14792 KB Output is correct
32 Correct 160 ms 14532 KB Output is correct
33 Correct 176 ms 14532 KB Output is correct
34 Correct 184 ms 14508 KB Output is correct
35 Correct 195 ms 14516 KB Output is correct
36 Correct 222 ms 14004 KB Output is correct
37 Correct 165 ms 14388 KB Output is correct
38 Correct 176 ms 15024 KB Output is correct
39 Correct 184 ms 14816 KB Output is correct
40 Correct 185 ms 14512 KB Output is correct
41 Correct 226 ms 15284 KB Output is correct
42 Correct 223 ms 14664 KB Output is correct
43 Correct 109 ms 14768 KB Output is correct
44 Correct 136 ms 15044 KB Output is correct
45 Correct 163 ms 14784 KB Output is correct
46 Correct 164 ms 14020 KB Output is correct
47 Correct 175 ms 14516 KB Output is correct
48 Correct 202 ms 14088 KB Output is correct
49 Correct 224 ms 15024 KB Output is correct
50 Correct 162 ms 14588 KB Output is correct
51 Correct 169 ms 14536 KB Output is correct
52 Correct 177 ms 15020 KB Output is correct
53 Correct 180 ms 14212 KB Output is correct
54 Correct 205 ms 14028 KB Output is correct
55 Correct 213 ms 15408 KB Output is correct
56 Correct 226 ms 15044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2584 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 89 ms 11212 KB Output is correct
56 Correct 111 ms 11208 KB Output is correct
57 Correct 143 ms 14272 KB Output is correct
58 Correct 167 ms 12992 KB Output is correct
59 Correct 184 ms 14416 KB Output is correct
60 Correct 197 ms 15052 KB Output is correct
61 Correct 147 ms 14788 KB Output is correct
62 Correct 157 ms 13556 KB Output is correct
63 Correct 158 ms 14084 KB Output is correct
64 Correct 186 ms 13760 KB Output is correct
65 Correct 204 ms 14528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2584 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 2 ms 2652 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 120 ms 11724 KB Output is correct
56 Correct 144 ms 11712 KB Output is correct
57 Correct 148 ms 14792 KB Output is correct
58 Correct 160 ms 14532 KB Output is correct
59 Correct 176 ms 14532 KB Output is correct
60 Correct 184 ms 14508 KB Output is correct
61 Correct 195 ms 14516 KB Output is correct
62 Correct 222 ms 14004 KB Output is correct
63 Correct 165 ms 14388 KB Output is correct
64 Correct 176 ms 15024 KB Output is correct
65 Correct 184 ms 14816 KB Output is correct
66 Correct 185 ms 14512 KB Output is correct
67 Correct 226 ms 15284 KB Output is correct
68 Correct 223 ms 14664 KB Output is correct
69 Correct 109 ms 14768 KB Output is correct
70 Correct 136 ms 15044 KB Output is correct
71 Correct 163 ms 14784 KB Output is correct
72 Correct 164 ms 14020 KB Output is correct
73 Correct 175 ms 14516 KB Output is correct
74 Correct 202 ms 14088 KB Output is correct
75 Correct 224 ms 15024 KB Output is correct
76 Correct 162 ms 14588 KB Output is correct
77 Correct 169 ms 14536 KB Output is correct
78 Correct 177 ms 15020 KB Output is correct
79 Correct 180 ms 14212 KB Output is correct
80 Correct 205 ms 14028 KB Output is correct
81 Correct 213 ms 15408 KB Output is correct
82 Correct 226 ms 15044 KB Output is correct
83 Correct 89 ms 11212 KB Output is correct
84 Correct 111 ms 11208 KB Output is correct
85 Correct 143 ms 14272 KB Output is correct
86 Correct 167 ms 12992 KB Output is correct
87 Correct 184 ms 14416 KB Output is correct
88 Correct 197 ms 15052 KB Output is correct
89 Correct 147 ms 14788 KB Output is correct
90 Correct 157 ms 13556 KB Output is correct
91 Correct 158 ms 14084 KB Output is correct
92 Correct 186 ms 13760 KB Output is correct
93 Correct 204 ms 14528 KB Output is correct
94 Correct 112 ms 14776 KB Output is correct
95 Correct 145 ms 15284 KB Output is correct
96 Correct 152 ms 15284 KB Output is correct
97 Correct 165 ms 15792 KB Output is correct
98 Correct 184 ms 15520 KB Output is correct
99 Correct 192 ms 15280 KB Output is correct
100 Correct 206 ms 15028 KB Output is correct
101 Correct 161 ms 14744 KB Output is correct
102 Correct 178 ms 14772 KB Output is correct
103 Correct 186 ms 15032 KB Output is correct
104 Correct 183 ms 14532 KB Output is correct
105 Correct 215 ms 14772 KB Output is correct
106 Correct 225 ms 16052 KB Output is correct
107 Correct 87 ms 16048 KB Output is correct
108 Correct 147 ms 15536 KB Output is correct
109 Correct 110 ms 14520 KB Output is correct
110 Correct 113 ms 15024 KB Output is correct
111 Correct 110 ms 15024 KB Output is correct
112 Correct 111 ms 14796 KB Output is correct
113 Correct 112 ms 14796 KB Output is correct
114 Correct 111 ms 14656 KB Output is correct
115 Correct 114 ms 14520 KB Output is correct
116 Correct 111 ms 15416 KB Output is correct