답안 #885537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885537 2023-12-10T02:47:20 Z huutuan Joker (BOI20_joker) C++14
100 / 100
425 ms 35900 KB
#include<bits/stdc++.h>
#define taskname "nohome"

using namespace std;

struct DSU{
   vector<int> lab, val;
   bool ans=1;
   vector<vector<pair<int, int>>> changes;
   void init(int n){
      lab.assign(n+1, -1);
      val.assign(n+1, 0);
   }
   pair<int, int> find_set(int u){
      if (lab[u]<0) return {u, 0};
      auto p=find_set(lab[u]);
      return {p.first, val[u]^p.second};
   }
   void union_sets(int u, int v){
      if (!u || !v) return;
      auto pu=find_set(u), pv=find_set(v);
      if (pu.first!=pv.first){
         if (lab[pu.first]>lab[pv.first]) swap(pu, pv), swap(u, v);
         changes.push_back({{pu.first, lab[pu.first]}, {pv.first, lab[pv.first]}, {pu.first, val[pu.first]}, {pv.first, val[pv.first]}});
         lab[pu.first]+=lab[pv.first];
         val[pu.first]=0;
         lab[pv.first]=pu.first;
         val[pv.first]=pu.second^pv.second^1;
      }else changes.push_back({{ans, -1}}), ans&=pu.second^pv.second;
   }
   void rollback(int sz){
      while ((int)changes.size()>sz){
         if (changes.back().size()==1){
            ans=changes.back()[0].first;
         }else{
            for (int i=0; i<2; ++i) lab[changes.back()[i].first]=changes.back()[i].second;
            for (int i=2; i<4; ++i) val[changes.back()[i].first]=changes.back()[i].second;
         }
         changes.pop_back();
      }
   }
} dsu;

const int N=2e5+1;
int n, m, q, ans[N], mx[N];
pair<int, int> edge[N];

void dnc(int l, int r, int optl, int optr){
   if (l>r) return;
   int mid=(l+r)>>1;
   int sz=dsu.changes.size();
   int idx=optr;
   for (int i=l; i<mid; ++i) dsu.union_sets(edge[i].first, edge[i].second);
   int sz2=dsu.changes.size();
   while (dsu.ans && idx>=optl){
      dsu.union_sets(edge[idx].first, edge[idx].second);
      --idx;
   }
   mx[mid]=idx;
   dsu.rollback(sz2);
   dsu.union_sets(edge[mid].first, edge[mid].second);
   dnc(mid+1, r, idx, optr);
   dsu.rollback(sz);
   for (int i=idx+1; i<=optr; ++i) dsu.union_sets(edge[i].first, edge[i].second);
   dnc(l, mid-1, optl, idx);
   dsu.rollback(sz);
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   // freopen(taskname".inp", "r", stdin);
   // freopen(taskname".out", "w", stdout);
   cin >> n >> m >> q;
   for (int i=1; i<=m; ++i){
      int x, y; cin >> x >> y;
      edge[i]={x, y};
   }
   dsu.init(n);
   dnc(1, m, 0, m);
   for (int i=1; i<=q; ++i){
      int l, r; cin >> l >> r;
      cout << (mx[l]>=r?"YES\n":"NO\n");
   }
   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2512 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2512 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2512 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2512 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2648 KB Output is correct
34 Correct 3 ms 2808 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 2904 KB Output is correct
40 Correct 2 ms 2648 KB Output is correct
41 Correct 2 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 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2704 KB Output is correct
49 Correct 2 ms 2708 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2640 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 172 ms 20936 KB Output is correct
4 Correct 406 ms 34936 KB Output is correct
5 Correct 148 ms 22928 KB Output is correct
6 Correct 156 ms 21492 KB Output is correct
7 Correct 165 ms 21752 KB Output is correct
8 Correct 185 ms 20112 KB Output is correct
9 Correct 203 ms 21532 KB Output is correct
10 Correct 251 ms 23548 KB Output is correct
11 Correct 209 ms 20868 KB Output is correct
12 Correct 214 ms 23644 KB Output is correct
13 Correct 190 ms 18576 KB Output is correct
14 Correct 177 ms 20028 KB Output is correct
15 Correct 244 ms 22284 KB Output is correct
16 Correct 257 ms 22612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2512 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2512 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 172 ms 20936 KB Output is correct
30 Correct 406 ms 34936 KB Output is correct
31 Correct 148 ms 22928 KB Output is correct
32 Correct 156 ms 21492 KB Output is correct
33 Correct 165 ms 21752 KB Output is correct
34 Correct 185 ms 20112 KB Output is correct
35 Correct 203 ms 21532 KB Output is correct
36 Correct 251 ms 23548 KB Output is correct
37 Correct 209 ms 20868 KB Output is correct
38 Correct 214 ms 23644 KB Output is correct
39 Correct 190 ms 18576 KB Output is correct
40 Correct 177 ms 20028 KB Output is correct
41 Correct 244 ms 22284 KB Output is correct
42 Correct 257 ms 22612 KB Output is correct
43 Correct 177 ms 21772 KB Output is correct
44 Correct 425 ms 35900 KB Output is correct
45 Correct 261 ms 23544 KB Output is correct
46 Correct 170 ms 22056 KB Output is correct
47 Correct 166 ms 20988 KB Output is correct
48 Correct 212 ms 20472 KB Output is correct
49 Correct 267 ms 22904 KB Output is correct
50 Correct 200 ms 20472 KB Output is correct
51 Correct 216 ms 23016 KB Output is correct
52 Correct 228 ms 24056 KB Output is correct
53 Correct 190 ms 20216 KB Output is correct
54 Correct 220 ms 20884 KB Output is correct
55 Correct 243 ms 22580 KB Output is correct
56 Correct 264 ms 23952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2512 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2512 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2648 KB Output is correct
34 Correct 3 ms 2808 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 2904 KB Output is correct
40 Correct 2 ms 2648 KB Output is correct
41 Correct 2 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 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2704 KB Output is correct
49 Correct 2 ms 2708 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2640 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 153 ms 18940 KB Output is correct
56 Correct 356 ms 32748 KB Output is correct
57 Correct 117 ms 21228 KB Output is correct
58 Correct 136 ms 19216 KB Output is correct
59 Correct 189 ms 18688 KB Output is correct
60 Correct 234 ms 20092 KB Output is correct
61 Correct 202 ms 18972 KB Output is correct
62 Correct 195 ms 21132 KB Output is correct
63 Correct 154 ms 17900 KB Output is correct
64 Correct 203 ms 19964 KB Output is correct
65 Correct 260 ms 20228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2512 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2512 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 2 ms 2652 KB Output is correct
33 Correct 2 ms 2648 KB Output is correct
34 Correct 3 ms 2808 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 3 ms 2656 KB Output is correct
39 Correct 2 ms 2904 KB Output is correct
40 Correct 2 ms 2648 KB Output is correct
41 Correct 2 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 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 2 ms 2704 KB Output is correct
49 Correct 2 ms 2708 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2652 KB Output is correct
52 Correct 2 ms 2640 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 172 ms 20936 KB Output is correct
56 Correct 406 ms 34936 KB Output is correct
57 Correct 148 ms 22928 KB Output is correct
58 Correct 156 ms 21492 KB Output is correct
59 Correct 165 ms 21752 KB Output is correct
60 Correct 185 ms 20112 KB Output is correct
61 Correct 203 ms 21532 KB Output is correct
62 Correct 251 ms 23548 KB Output is correct
63 Correct 209 ms 20868 KB Output is correct
64 Correct 214 ms 23644 KB Output is correct
65 Correct 190 ms 18576 KB Output is correct
66 Correct 177 ms 20028 KB Output is correct
67 Correct 244 ms 22284 KB Output is correct
68 Correct 257 ms 22612 KB Output is correct
69 Correct 177 ms 21772 KB Output is correct
70 Correct 425 ms 35900 KB Output is correct
71 Correct 261 ms 23544 KB Output is correct
72 Correct 170 ms 22056 KB Output is correct
73 Correct 166 ms 20988 KB Output is correct
74 Correct 212 ms 20472 KB Output is correct
75 Correct 267 ms 22904 KB Output is correct
76 Correct 200 ms 20472 KB Output is correct
77 Correct 216 ms 23016 KB Output is correct
78 Correct 228 ms 24056 KB Output is correct
79 Correct 190 ms 20216 KB Output is correct
80 Correct 220 ms 20884 KB Output is correct
81 Correct 243 ms 22580 KB Output is correct
82 Correct 264 ms 23952 KB Output is correct
83 Correct 153 ms 18940 KB Output is correct
84 Correct 356 ms 32748 KB Output is correct
85 Correct 117 ms 21228 KB Output is correct
86 Correct 136 ms 19216 KB Output is correct
87 Correct 189 ms 18688 KB Output is correct
88 Correct 234 ms 20092 KB Output is correct
89 Correct 202 ms 18972 KB Output is correct
90 Correct 195 ms 21132 KB Output is correct
91 Correct 154 ms 17900 KB Output is correct
92 Correct 203 ms 19964 KB Output is correct
93 Correct 260 ms 20228 KB Output is correct
94 Correct 185 ms 22740 KB Output is correct
95 Correct 211 ms 23964 KB Output is correct
96 Correct 145 ms 24832 KB Output is correct
97 Correct 172 ms 22104 KB Output is correct
98 Correct 173 ms 22012 KB Output is correct
99 Correct 201 ms 21964 KB Output is correct
100 Correct 249 ms 23688 KB Output is correct
101 Correct 203 ms 21244 KB Output is correct
102 Correct 237 ms 22560 KB Output is correct
103 Correct 273 ms 24008 KB Output is correct
104 Correct 190 ms 20752 KB Output is correct
105 Correct 236 ms 23028 KB Output is correct
106 Correct 263 ms 23772 KB Output is correct
107 Correct 140 ms 25728 KB Output is correct
108 Correct 180 ms 22160 KB Output is correct
109 Correct 178 ms 22108 KB Output is correct
110 Correct 173 ms 21496 KB Output is correct
111 Correct 172 ms 21724 KB Output is correct
112 Correct 194 ms 22868 KB Output is correct
113 Correct 176 ms 21548 KB Output is correct
114 Correct 173 ms 22812 KB Output is correct
115 Correct 184 ms 21496 KB Output is correct
116 Correct 180 ms 21664 KB Output is correct