답안 #1093665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093665 2024-09-27T08:06:06 Z zNatsumi Joker (BOI20_joker) C++17
49 / 100
782 ms 20156 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,
          block = 448;

int n, m, q;
ii edge[N];
bool pre, res[N];
int pa[N], sz[N], lz[N], it;
pair<int*, int> trace[3*N];
vector<tp> que[448 + 5];

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

bool uset(int u, int v){
  int cu = 0, cv = 0;
  u = fset(u, cu);
  v = fset(v, cv);
  if(u == v){
    if(cu == cv) return true;
    return false;
  }
  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;
  }
  return false;
}

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

int getblock(int i){
  return (i - 1) / block + 1;
}

void solve(int b, vector<tp> &query){
  int lst = m;
  int flag = it;

  bool val = false;
  for(auto x : query){
    int l, r, idx; tie(r, l, idx) = x;

    if(r <= b*block){
      for(int i = lst; i > b * block; i--) val |= uset(edge[i].fi, edge[i].se);
      lst = b * block;

      int tmp = it;
      bool ok = false;

      for(int i = (b - 1) * block + 1; i <= min(b * block, m); i++){
        if(l <= i && i <= r) continue;

        if(uset(edge[i].fi, edge[i].se)){
          ok = true;
          break;
        }
      }
      res[idx] = ok | val | pre;
      rollback(tmp);
    }else{
      for(int i = lst; i > r; i--)
        val |= uset(edge[i].fi, edge[i].se);

      lst = r;

      int tmp = it;
      bool dd = false;
      for(int i = (b - 1) * block + 1; i < l; i++) dd |= uset(edge[i].fi, edge[i].se);


      res[idx] = dd | val | pre;
      rollback(tmp);
    }
  }
  rollback(flag);
  for(int i = (b - 1) * block + 1; i <= min(b * block, m); i++) pre |= uset(edge[i].fi, edge[i].se);
}

int32_t main(){
  cin.tie(0)->sync_with_stdio(0);
//  #define task "test"
//  if(fopen(task ".inp", "r")){
//    freopen(task ".inp", "r", stdin);
//    freopen(task ".out", "w", stdout);
//  }

  cin >> n >> m >> q;
  for(int i = 1; i <= m; i++){
    int u, v; cin >> u >> v;
    edge[i] = {u, v};
  }

  for(int t = 1; t <= q; t++){
    int l, r; cin >> l >> r;
    que[getblock(l)].push_back({r, l, t});
  }
  for(int i = 1; i <= 448; i++) sort(all(que[i]), greater<>());

  for(int i = 1; i <= n; i++){
    pa[i] = i;
    sz[i] = 1;
    lz[i] = 0;
  }
  for(int i = 1; i <= 20; i++){
    solve(i, que[i]);
  }


  for(int i = 1; i <= q; i++) cout << (res[i] ? "YES\n" : "NO\n");

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 8 ms 600 KB Output is correct
30 Correct 5 ms 600 KB Output is correct
31 Correct 4 ms 604 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 5 ms 532 KB Output is correct
35 Correct 5 ms 604 KB Output is correct
36 Correct 4 ms 656 KB Output is correct
37 Correct 6 ms 488 KB Output is correct
38 Correct 8 ms 604 KB Output is correct
39 Correct 4 ms 604 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 4 ms 604 KB Output is correct
42 Correct 4 ms 604 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 2 ms 600 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 4 ms 536 KB Output is correct
50 Correct 4 ms 544 KB Output is correct
51 Correct 4 ms 600 KB Output is correct
52 Correct 4 ms 652 KB Output is correct
53 Correct 4 ms 600 KB Output is correct
54 Correct 5 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 64 ms 14276 KB Output is correct
4 Correct 719 ms 19128 KB Output is correct
5 Correct 75 ms 18976 KB Output is correct
6 Correct 69 ms 14528 KB Output is correct
7 Correct 68 ms 14528 KB Output is correct
8 Correct 67 ms 11968 KB Output is correct
9 Correct 67 ms 13996 KB Output is correct
10 Correct 72 ms 18308 KB Output is correct
11 Correct 67 ms 14524 KB Output is correct
12 Correct 69 ms 18108 KB Output is correct
13 Correct 64 ms 10160 KB Output is correct
14 Correct 65 ms 12476 KB Output is correct
15 Correct 69 ms 16316 KB Output is correct
16 Correct 71 ms 18616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 64 ms 14276 KB Output is correct
30 Correct 719 ms 19128 KB Output is correct
31 Correct 75 ms 18976 KB Output is correct
32 Correct 69 ms 14528 KB Output is correct
33 Correct 68 ms 14528 KB Output is correct
34 Correct 67 ms 11968 KB Output is correct
35 Correct 67 ms 13996 KB Output is correct
36 Correct 72 ms 18308 KB Output is correct
37 Correct 67 ms 14524 KB Output is correct
38 Correct 69 ms 18108 KB Output is correct
39 Correct 64 ms 10160 KB Output is correct
40 Correct 65 ms 12476 KB Output is correct
41 Correct 69 ms 16316 KB Output is correct
42 Correct 71 ms 18616 KB Output is correct
43 Correct 239 ms 14520 KB Output is correct
44 Correct 782 ms 19832 KB Output is correct
45 Correct 280 ms 20156 KB Output is correct
46 Correct 243 ms 14740 KB Output is correct
47 Correct 282 ms 14780 KB Output is correct
48 Correct 131 ms 14524 KB Output is correct
49 Correct 157 ms 18616 KB Output is correct
50 Correct 204 ms 13756 KB Output is correct
51 Correct 259 ms 16764 KB Output is correct
52 Correct 284 ms 18872 KB Output is correct
53 Correct 202 ms 10428 KB Output is correct
54 Correct 325 ms 13756 KB Output is correct
55 Correct 357 ms 16820 KB Output is correct
56 Correct 382 ms 18872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 8 ms 600 KB Output is correct
30 Correct 5 ms 600 KB Output is correct
31 Correct 4 ms 604 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 5 ms 532 KB Output is correct
35 Correct 5 ms 604 KB Output is correct
36 Correct 4 ms 656 KB Output is correct
37 Correct 6 ms 488 KB Output is correct
38 Correct 8 ms 604 KB Output is correct
39 Correct 4 ms 604 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 4 ms 604 KB Output is correct
42 Correct 4 ms 604 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 2 ms 600 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 4 ms 536 KB Output is correct
50 Correct 4 ms 544 KB Output is correct
51 Correct 4 ms 600 KB Output is correct
52 Correct 4 ms 652 KB Output is correct
53 Correct 4 ms 600 KB Output is correct
54 Correct 5 ms 604 KB Output is correct
55 Incorrect 62 ms 9296 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 8 ms 600 KB Output is correct
30 Correct 5 ms 600 KB Output is correct
31 Correct 4 ms 604 KB Output is correct
32 Correct 4 ms 640 KB Output is correct
33 Correct 4 ms 604 KB Output is correct
34 Correct 5 ms 532 KB Output is correct
35 Correct 5 ms 604 KB Output is correct
36 Correct 4 ms 656 KB Output is correct
37 Correct 6 ms 488 KB Output is correct
38 Correct 8 ms 604 KB Output is correct
39 Correct 4 ms 604 KB Output is correct
40 Correct 4 ms 604 KB Output is correct
41 Correct 4 ms 604 KB Output is correct
42 Correct 4 ms 604 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 2 ms 600 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 4 ms 536 KB Output is correct
50 Correct 4 ms 544 KB Output is correct
51 Correct 4 ms 600 KB Output is correct
52 Correct 4 ms 652 KB Output is correct
53 Correct 4 ms 600 KB Output is correct
54 Correct 5 ms 604 KB Output is correct
55 Correct 64 ms 14276 KB Output is correct
56 Correct 719 ms 19128 KB Output is correct
57 Correct 75 ms 18976 KB Output is correct
58 Correct 69 ms 14528 KB Output is correct
59 Correct 68 ms 14528 KB Output is correct
60 Correct 67 ms 11968 KB Output is correct
61 Correct 67 ms 13996 KB Output is correct
62 Correct 72 ms 18308 KB Output is correct
63 Correct 67 ms 14524 KB Output is correct
64 Correct 69 ms 18108 KB Output is correct
65 Correct 64 ms 10160 KB Output is correct
66 Correct 65 ms 12476 KB Output is correct
67 Correct 69 ms 16316 KB Output is correct
68 Correct 71 ms 18616 KB Output is correct
69 Correct 239 ms 14520 KB Output is correct
70 Correct 782 ms 19832 KB Output is correct
71 Correct 280 ms 20156 KB Output is correct
72 Correct 243 ms 14740 KB Output is correct
73 Correct 282 ms 14780 KB Output is correct
74 Correct 131 ms 14524 KB Output is correct
75 Correct 157 ms 18616 KB Output is correct
76 Correct 204 ms 13756 KB Output is correct
77 Correct 259 ms 16764 KB Output is correct
78 Correct 284 ms 18872 KB Output is correct
79 Correct 202 ms 10428 KB Output is correct
80 Correct 325 ms 13756 KB Output is correct
81 Correct 357 ms 16820 KB Output is correct
82 Correct 382 ms 18872 KB Output is correct
83 Incorrect 62 ms 9296 KB Output isn't correct
84 Halted 0 ms 0 KB -