답안 #933204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933204 2024-02-25T09:05:13 Z Erfan1386Y Joker (BOI20_joker) C++17
100 / 100
229 ms 13004 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << endl; continue;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;
 
using namespace std;

const int N = 2e5 + 10, LG = 40;
int par[N], sz[N], col[N], cnt, L, R, ans[N];
vector<pii> st;
pii edges[N];

int root (int &v) {
  int res = 0;
  while (par[v] != v) 
    res ^= col[v], v = par[v];
  return res;
}
void mrg (pii e) {
  auto [v, u] = e;
  int r1 = root(v) , r2 = root(u);
  if (v == u) {
    if (r1 == r2) st.pb(pii(-2 , -2)), cnt++;
    else st.pb(pii(-1 , -1));
    return;
  }
  if (sz[v] < sz[u]) swap(v , u);
  par[u] = v;
  sz[v] += sz[u];
  st.pb(pii(v , u));
  col[u] = r1 ^ r2 ^ 1;
}

void undo() {
  pii e = st.back();
  st.pop_back();
  if(e.F == -1) return;
  if(e.F == -2) {--cnt; return;}
  col[e.S] = 0;
  par[e.S] = e.S;
  sz[e.F] -= sz[e.S];
}

void solve (int a, int b, int x, int y) {
  if (a > b) return;
  int save = st.size();
  int mid = (a + b) >> 1;
  while (L < mid) mrg(edges[L++]);
  while (R > mid && !cnt) mrg(edges[R--]);
  ans[mid] = R;
  if (cnt == 0) ans[mid]--;
  while (st.size() > save) undo();
  L = a, R = y;
  while (L <= mid) mrg(edges[L++]);
  solve(mid + 1, b, ans[mid], y);
  while (st.size() > save) undo();
  L = a, R = y;
  while (R > ans[mid]) mrg(edges[R--]);
  solve(a, mid - 1, x, ans[mid]);
  while (st.size() > save) undo();
  L = a, R = y;
}

int main () {
  fast_io;
  int n, m, q;
  cin >> n >> m >> q;
  L = 1, R = m;
  fill(sz + 1, sz + n + 1, 1);
  iota(par + 1, par + n + 1, 1);
  for (int i = 1; i <= m; i++) {
    cin >> edges[i].F >> edges[i].S;
  }
  solve(1, m, 1, m);
  while (q--) {
    int l, r;
    cin >> l >> r;
    if (r > ans[l]) cout << "NO\n";
    else cout << "YES\n";
  }
  return 0;
}

Compilation message

Joker.cpp: In function 'void solve(int, int, int, int)':
Joker.cpp:60:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |   while (st.size() > save) undo();
      |          ~~~~~~~~~~^~~~~~
Joker.cpp:64:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |   while (st.size() > save) undo();
      |          ~~~~~~~~~~^~~~~~
Joker.cpp:68:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |   while (st.size() > save) undo();
      |          ~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 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 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4564 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4528 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 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 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 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 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4564 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4528 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 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 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
29 Correct 2 ms 4448 KB Output is correct
30 Correct 2 ms 4584 KB Output is correct
31 Correct 2 ms 4656 KB Output is correct
32 Correct 2 ms 4448 KB Output is correct
33 Correct 2 ms 4448 KB Output is correct
34 Correct 2 ms 4448 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4664 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 2 ms 4444 KB Output is correct
39 Correct 2 ms 4440 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 4576 KB Output is correct
43 Correct 2 ms 4448 KB Output is correct
44 Correct 2 ms 4440 KB Output is correct
45 Correct 3 ms 4624 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4572 KB Output is correct
48 Correct 2 ms 4440 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 3 ms 4444 KB Output is correct
52 Correct 3 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 2 ms 4444 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 124 ms 11044 KB Output is correct
4 Correct 205 ms 10812 KB Output is correct
5 Correct 122 ms 11460 KB Output is correct
6 Correct 165 ms 10948 KB Output is correct
7 Correct 168 ms 11068 KB Output is correct
8 Correct 204 ms 10392 KB Output is correct
9 Correct 188 ms 10544 KB Output is correct
10 Correct 219 ms 11060 KB Output is correct
11 Correct 179 ms 10784 KB Output is correct
12 Correct 188 ms 11360 KB Output is correct
13 Correct 176 ms 10696 KB Output is correct
14 Correct 186 ms 10952 KB Output is correct
15 Correct 229 ms 11204 KB Output is correct
16 Correct 218 ms 11460 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 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4564 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4528 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 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 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
29 Correct 124 ms 11044 KB Output is correct
30 Correct 205 ms 10812 KB Output is correct
31 Correct 122 ms 11460 KB Output is correct
32 Correct 165 ms 10948 KB Output is correct
33 Correct 168 ms 11068 KB Output is correct
34 Correct 204 ms 10392 KB Output is correct
35 Correct 188 ms 10544 KB Output is correct
36 Correct 219 ms 11060 KB Output is correct
37 Correct 179 ms 10784 KB Output is correct
38 Correct 188 ms 11360 KB Output is correct
39 Correct 176 ms 10696 KB Output is correct
40 Correct 186 ms 10952 KB Output is correct
41 Correct 229 ms 11204 KB Output is correct
42 Correct 218 ms 11460 KB Output is correct
43 Correct 128 ms 11208 KB Output is correct
44 Correct 195 ms 11320 KB Output is correct
45 Correct 172 ms 11768 KB Output is correct
46 Correct 156 ms 11208 KB Output is correct
47 Correct 157 ms 11316 KB Output is correct
48 Correct 207 ms 10864 KB Output is correct
49 Correct 219 ms 11492 KB Output is correct
50 Correct 176 ms 11136 KB Output is correct
51 Correct 179 ms 11548 KB Output is correct
52 Correct 182 ms 11720 KB Output is correct
53 Correct 183 ms 10976 KB Output is correct
54 Correct 200 ms 11208 KB Output is correct
55 Correct 224 ms 11608 KB Output is correct
56 Correct 223 ms 11976 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 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4564 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4528 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 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 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
29 Correct 2 ms 4448 KB Output is correct
30 Correct 2 ms 4584 KB Output is correct
31 Correct 2 ms 4656 KB Output is correct
32 Correct 2 ms 4448 KB Output is correct
33 Correct 2 ms 4448 KB Output is correct
34 Correct 2 ms 4448 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4664 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 2 ms 4444 KB Output is correct
39 Correct 2 ms 4440 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 4576 KB Output is correct
43 Correct 2 ms 4448 KB Output is correct
44 Correct 2 ms 4440 KB Output is correct
45 Correct 3 ms 4624 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4572 KB Output is correct
48 Correct 2 ms 4440 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 3 ms 4444 KB Output is correct
52 Correct 3 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 98 ms 9168 KB Output is correct
56 Correct 173 ms 9824 KB Output is correct
57 Correct 103 ms 9676 KB Output is correct
58 Correct 134 ms 9164 KB Output is correct
59 Correct 173 ms 9164 KB Output is correct
60 Correct 197 ms 9684 KB Output is correct
61 Correct 150 ms 9164 KB Output is correct
62 Correct 187 ms 9536 KB Output is correct
63 Correct 151 ms 9060 KB Output is correct
64 Correct 178 ms 9436 KB Output is correct
65 Correct 182 ms 9676 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 2 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4564 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4564 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 3 ms 4528 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4560 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 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4440 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 4444 KB Output is correct
29 Correct 2 ms 4448 KB Output is correct
30 Correct 2 ms 4584 KB Output is correct
31 Correct 2 ms 4656 KB Output is correct
32 Correct 2 ms 4448 KB Output is correct
33 Correct 2 ms 4448 KB Output is correct
34 Correct 2 ms 4448 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 2 ms 4664 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 2 ms 4444 KB Output is correct
39 Correct 2 ms 4440 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 4576 KB Output is correct
43 Correct 2 ms 4448 KB Output is correct
44 Correct 2 ms 4440 KB Output is correct
45 Correct 3 ms 4624 KB Output is correct
46 Correct 2 ms 4440 KB Output is correct
47 Correct 2 ms 4572 KB Output is correct
48 Correct 2 ms 4440 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 3 ms 4444 KB Output is correct
52 Correct 3 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 124 ms 11044 KB Output is correct
56 Correct 205 ms 10812 KB Output is correct
57 Correct 122 ms 11460 KB Output is correct
58 Correct 165 ms 10948 KB Output is correct
59 Correct 168 ms 11068 KB Output is correct
60 Correct 204 ms 10392 KB Output is correct
61 Correct 188 ms 10544 KB Output is correct
62 Correct 219 ms 11060 KB Output is correct
63 Correct 179 ms 10784 KB Output is correct
64 Correct 188 ms 11360 KB Output is correct
65 Correct 176 ms 10696 KB Output is correct
66 Correct 186 ms 10952 KB Output is correct
67 Correct 229 ms 11204 KB Output is correct
68 Correct 218 ms 11460 KB Output is correct
69 Correct 128 ms 11208 KB Output is correct
70 Correct 195 ms 11320 KB Output is correct
71 Correct 172 ms 11768 KB Output is correct
72 Correct 156 ms 11208 KB Output is correct
73 Correct 157 ms 11316 KB Output is correct
74 Correct 207 ms 10864 KB Output is correct
75 Correct 219 ms 11492 KB Output is correct
76 Correct 176 ms 11136 KB Output is correct
77 Correct 179 ms 11548 KB Output is correct
78 Correct 182 ms 11720 KB Output is correct
79 Correct 183 ms 10976 KB Output is correct
80 Correct 200 ms 11208 KB Output is correct
81 Correct 224 ms 11608 KB Output is correct
82 Correct 223 ms 11976 KB Output is correct
83 Correct 98 ms 9168 KB Output is correct
84 Correct 173 ms 9824 KB Output is correct
85 Correct 103 ms 9676 KB Output is correct
86 Correct 134 ms 9164 KB Output is correct
87 Correct 173 ms 9164 KB Output is correct
88 Correct 197 ms 9684 KB Output is correct
89 Correct 150 ms 9164 KB Output is correct
90 Correct 187 ms 9536 KB Output is correct
91 Correct 151 ms 9060 KB Output is correct
92 Correct 178 ms 9436 KB Output is correct
93 Correct 182 ms 9676 KB Output is correct
94 Correct 137 ms 11900 KB Output is correct
95 Correct 199 ms 12680 KB Output is correct
96 Correct 127 ms 12916 KB Output is correct
97 Correct 181 ms 12084 KB Output is correct
98 Correct 162 ms 11972 KB Output is correct
99 Correct 192 ms 12040 KB Output is correct
100 Correct 201 ms 12484 KB Output is correct
101 Correct 169 ms 12056 KB Output is correct
102 Correct 201 ms 12340 KB Output is correct
103 Correct 213 ms 12592 KB Output is correct
104 Correct 185 ms 11976 KB Output is correct
105 Correct 214 ms 12156 KB Output is correct
106 Correct 216 ms 13004 KB Output is correct
107 Correct 109 ms 12740 KB Output is correct
108 Correct 124 ms 11840 KB Output is correct
109 Correct 125 ms 11716 KB Output is correct
110 Correct 125 ms 11884 KB Output is correct
111 Correct 127 ms 11896 KB Output is correct
112 Correct 124 ms 11824 KB Output is correct
113 Correct 126 ms 11720 KB Output is correct
114 Correct 135 ms 11716 KB Output is correct
115 Correct 124 ms 11716 KB Output is correct
116 Correct 130 ms 11648 KB Output is correct