답안 #1093791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093791 2024-09-27T13:27:22 Z zNatsumi Joker (BOI20_joker) C++17
100 / 100
176 ms 20308 KB
#include <bits/stdc++.h>

using namespace std;

#define ii pair<int, int>
#define tp tuple<int, int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()

const int N = 2e5 + 5;

int n, m, q, lst[N], cur = false;
ii edge[N];
int pa[N], sz[N], lz[N], it;
pair<int*, int> trace[3*N];

int fset(int i, int &c){
  c ^= lz[i];
  return i == pa[i] ? i : fset(pa[i], c);
}

void uset(int u, int v){
  int cu = 0, cv = 0;
  u = fset(u, cu);
  v = fset(v, cv);
  if(u == v){
    if(cu == cv){
      trace[it++] = {&cur, cur};
      cur = true;
    }
    return;
  }
  if(sz[u] < sz[v]) swap(u, v);
  trace[it++] = {pa + v, pa[v]}; pa[v] = u;
  trace[it++] = {sz + u, sz[u]}; sz[u] += sz[v];
  if(cu == cv){
    trace[it++] = {lz + v, lz[v]};
    lz[v] ^= 1;
  }
}

void rollback(int t){
  for(; it > t; ){
    it--;
    *trace[it].fi = trace[it].se;
  }
}

void dnc(int l, int r, int optl, int optr){
  if(l > r) return;

  int mid = l + r >> 1,
      ti1 = it,
      opt = m + 1;

  for(int i = l; i < mid; i++) uset(edge[i].fi, edge[i].se);

  int ti2 = it;

  if(!cur){
    for(int i = min(optr, m); i >= max(mid, optl); i--){
      uset(edge[i].fi, edge[i].se);
      opt = i;
      if(cur) break;
    }
  }
  lst[mid] = opt;
  opt = min(opt, m);

  rollback(ti2);
  uset(edge[mid].fi, edge[mid].se);
  dnc(mid + 1, r, opt, optr);

  rollback(ti1);
  for(int i = max(r, optr); i > opt; i--) uset(edge[i].fi, edge[i].se);
  dnc(l, mid - 1, optl, opt);

  rollback(ti1);
}

int32_t main(){
  cin.tie(0)->sync_with_stdio(0);
 
  cin >> n >> m >> q;
  for(int i = 1; i <= m; i++){
    int u, v; cin >> u >> v;
    edge[i] = {u, v};
  }

  for(int i = 1; i <= n; i++){
    pa[i] = i;
    sz[i] = 1;
    lz[i] = 0;
  }
  dnc(1, m, 1, m);
//  for(int i = 1; i <= m; i++) cout << lst[i] << " \n"[i == m];

  while(q--){
    int l, r; cin >> l >> r;

    cout << (r < lst[l] ? "YES\n" : "NO\n");
  }

  return 0;
}

Compilation message

Joker.cpp: In function 'void dnc(int, int, int, int)':
Joker.cpp:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |   int mid = l + r >> 1,
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 1 ms 520 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 636 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 624 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 92 ms 13904 KB Output is correct
4 Correct 170 ms 17400 KB Output is correct
5 Correct 93 ms 17000 KB Output is correct
6 Correct 103 ms 13136 KB Output is correct
7 Correct 108 ms 13132 KB Output is correct
8 Correct 111 ms 10820 KB Output is correct
9 Correct 125 ms 12624 KB Output is correct
10 Correct 158 ms 16576 KB Output is correct
11 Correct 117 ms 13136 KB Output is correct
12 Correct 140 ms 16448 KB Output is correct
13 Correct 109 ms 9048 KB Output is correct
14 Correct 113 ms 11348 KB Output is correct
15 Correct 162 ms 14932 KB Output is correct
16 Correct 164 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 92 ms 13904 KB Output is correct
30 Correct 170 ms 17400 KB Output is correct
31 Correct 93 ms 17000 KB Output is correct
32 Correct 103 ms 13136 KB Output is correct
33 Correct 108 ms 13132 KB Output is correct
34 Correct 111 ms 10820 KB Output is correct
35 Correct 125 ms 12624 KB Output is correct
36 Correct 158 ms 16576 KB Output is correct
37 Correct 117 ms 13136 KB Output is correct
38 Correct 140 ms 16448 KB Output is correct
39 Correct 109 ms 9048 KB Output is correct
40 Correct 113 ms 11348 KB Output is correct
41 Correct 162 ms 14932 KB Output is correct
42 Correct 164 ms 16980 KB Output is correct
43 Correct 96 ms 14164 KB Output is correct
44 Correct 176 ms 17748 KB Output is correct
45 Correct 144 ms 18132 KB Output is correct
46 Correct 106 ms 13524 KB Output is correct
47 Correct 106 ms 13648 KB Output is correct
48 Correct 135 ms 13140 KB Output is correct
49 Correct 166 ms 17132 KB Output is correct
50 Correct 112 ms 12368 KB Output is correct
51 Correct 124 ms 15188 KB Output is correct
52 Correct 134 ms 16968 KB Output is correct
53 Correct 109 ms 9380 KB Output is correct
54 Correct 138 ms 12660 KB Output is correct
55 Correct 156 ms 15196 KB Output is correct
56 Correct 162 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 1 ms 520 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 636 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 624 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 74 ms 11724 KB Output is correct
56 Correct 138 ms 15696 KB Output is correct
57 Correct 65 ms 14388 KB Output is correct
58 Correct 89 ms 10832 KB Output is correct
59 Correct 111 ms 10956 KB Output is correct
60 Correct 139 ms 13524 KB Output is correct
61 Correct 104 ms 10812 KB Output is correct
62 Correct 114 ms 14048 KB Output is correct
63 Correct 86 ms 7760 KB Output is correct
64 Correct 124 ms 11860 KB Output is correct
65 Correct 148 ms 14160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 464 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 620 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 1 ms 520 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 636 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 624 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 92 ms 13904 KB Output is correct
56 Correct 170 ms 17400 KB Output is correct
57 Correct 93 ms 17000 KB Output is correct
58 Correct 103 ms 13136 KB Output is correct
59 Correct 108 ms 13132 KB Output is correct
60 Correct 111 ms 10820 KB Output is correct
61 Correct 125 ms 12624 KB Output is correct
62 Correct 158 ms 16576 KB Output is correct
63 Correct 117 ms 13136 KB Output is correct
64 Correct 140 ms 16448 KB Output is correct
65 Correct 109 ms 9048 KB Output is correct
66 Correct 113 ms 11348 KB Output is correct
67 Correct 162 ms 14932 KB Output is correct
68 Correct 164 ms 16980 KB Output is correct
69 Correct 96 ms 14164 KB Output is correct
70 Correct 176 ms 17748 KB Output is correct
71 Correct 144 ms 18132 KB Output is correct
72 Correct 106 ms 13524 KB Output is correct
73 Correct 106 ms 13648 KB Output is correct
74 Correct 135 ms 13140 KB Output is correct
75 Correct 166 ms 17132 KB Output is correct
76 Correct 112 ms 12368 KB Output is correct
77 Correct 124 ms 15188 KB Output is correct
78 Correct 134 ms 16968 KB Output is correct
79 Correct 109 ms 9380 KB Output is correct
80 Correct 138 ms 12660 KB Output is correct
81 Correct 156 ms 15196 KB Output is correct
82 Correct 162 ms 17232 KB Output is correct
83 Correct 74 ms 11724 KB Output is correct
84 Correct 138 ms 15696 KB Output is correct
85 Correct 65 ms 14388 KB Output is correct
86 Correct 89 ms 10832 KB Output is correct
87 Correct 111 ms 10956 KB Output is correct
88 Correct 139 ms 13524 KB Output is correct
89 Correct 104 ms 10812 KB Output is correct
90 Correct 114 ms 14048 KB Output is correct
91 Correct 86 ms 7760 KB Output is correct
92 Correct 124 ms 11860 KB Output is correct
93 Correct 148 ms 14160 KB Output is correct
94 Correct 102 ms 14928 KB Output is correct
95 Correct 132 ms 18768 KB Output is correct
96 Correct 105 ms 17752 KB Output is correct
97 Correct 109 ms 14164 KB Output is correct
98 Correct 118 ms 14364 KB Output is correct
99 Correct 120 ms 12116 KB Output is correct
100 Correct 155 ms 18096 KB Output is correct
101 Correct 117 ms 13104 KB Output is correct
102 Correct 137 ms 16000 KB Output is correct
103 Correct 148 ms 17748 KB Output is correct
104 Correct 114 ms 11092 KB Output is correct
105 Correct 149 ms 15076 KB Output is correct
106 Correct 167 ms 17488 KB Output is correct
107 Correct 71 ms 20308 KB Output is correct
108 Correct 117 ms 14676 KB Output is correct
109 Correct 94 ms 14672 KB Output is correct
110 Correct 101 ms 14672 KB Output is correct
111 Correct 96 ms 14688 KB Output is correct
112 Correct 96 ms 14812 KB Output is correct
113 Correct 96 ms 14672 KB Output is correct
114 Correct 95 ms 14760 KB Output is correct
115 Correct 97 ms 14672 KB Output is correct
116 Correct 96 ms 14828 KB Output is correct