답안 #1093579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093579 2024-09-27T04:14:17 Z zNatsumi Joker (BOI20_joker) C++17
6 / 100
731 ms 19276 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[block + 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--) uset(edge[i].fi, edge[i].se);
      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;
      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 <= block; 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 <= block; 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 528 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 344 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 476 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 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 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 528 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 344 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 476 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 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 604 KB Output is correct
30 Incorrect 5 ms 604 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 66 ms 14464 KB Output is correct
4 Correct 731 ms 19276 KB Output is correct
5 Correct 77 ms 18876 KB Output is correct
6 Correct 74 ms 14504 KB Output is correct
7 Correct 75 ms 14504 KB Output is correct
8 Incorrect 77 ms 11968 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 528 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 344 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 476 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 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 66 ms 14464 KB Output is correct
30 Correct 731 ms 19276 KB Output is correct
31 Correct 77 ms 18876 KB Output is correct
32 Correct 74 ms 14504 KB Output is correct
33 Correct 75 ms 14504 KB Output is correct
34 Incorrect 77 ms 11968 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 528 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 344 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 476 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 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 604 KB Output is correct
30 Incorrect 5 ms 604 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 528 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 344 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 476 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 0 ms 348 KB Output is correct
26 Correct 0 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 604 KB Output is correct
30 Incorrect 5 ms 604 KB Output isn't correct
31 Halted 0 ms 0 KB -