QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#55358 | #4863. Equivalence in Connectivity | zhoukangyang# | AC ✓ | 279ms | 180256kb | C++11 | 3.0kb | 2022-10-13 12:31:28 | 2022-10-13 12:31:31 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
using namespace std;
const int N = 2e6 + 7;
mt19937_64 orz(time(0) ^ (*new char));
int stk[N], tp, id[N];
ull xw[N];
int f[N], siz[N];
inline int find(int x) {
return f[x] == x ? x : find(f[x]);
}
ull SUM;
inline void revoke() {
int u = stk[tp];
siz[f[u]] -= siz[u], SUM ^= xw[f[u]], xw[f[u]] -= xw[u];
SUM ^= xw[f[u]] ^ xw[u], f[u] = u, --tp;
}
ull ns[N];
vector < pair < int, int > > sol[N];
inline void dc(int x, int l, int r) {
int mid = (l + r) >> 1, lt = tp;
for(auto u : sol[x]) {
int x = find(u.first), y = find(u.second);
if(siz[x] > siz[y]) swap(x, y);
if(x == y) continue;
SUM ^= xw[x] ^ xw[y];
f[x] = y, siz[y] += siz[x], xw[y] += xw[x], stk[++tp] = x;
SUM ^= xw[y];
}
if(l == r) {
ns[id[l]] = SUM;
// cout << "SUM = " << SUM << '\n';
} else {
dc(x << 1, l, mid), dc(x << 1 | 1, mid + 1, r);
}
sol[x].clear();
while(tp > lt) revoke();
}
void mark(int x, int L, int R, int l, int r, pair < int, int > pr) {
if(l <= L && R <= r) return sol[x].push_back(pr), void();
int mid = (L + R) >> 1;
if(l <= mid) mark(x << 1, L, mid, l, r, pr);
if(r > mid) mark(x << 1 | 1, mid + 1, R, l, r, pr);
}
int n, m, k, tot = 1;
vi e[N];
map < pair < int, int >, int > mp;
string str[N];
int xu[N], xv[N];
void lk(int u, int v, int t) {
mp[make_pair(u, v)] = t;
}
void del(int u, int v, int t) {
int ti = mp[make_pair(u, v)];
if(ti < t) mark(1, 1, k, ti, t - 1, {u, v});
mp.erase(make_pair(u, v));
}
void dfs(int x) {
if(xu[x] > xv[x]) swap(xu[x], xv[x]);
if(x > 1) {
++tot;
if(str[x] == "add") lk(xu[x], xv[x], tot);
if(str[x] == "remove") del(xu[x], xv[x], tot);
}
id[tot] = x;
for(const int &v : e[x]) dfs(v);
if(x > 1) {
if(str[x] == "add") del(xu[x], xv[x], tot + 1);
if(str[x] == "remove") lk(xu[x], xv[x], tot + 1);
}
}
map < ull, vi > ovo;
void Main() {
mp.clear(), ovo.clear();
cin >> k >> n >> m, SUM = 0;
L(i, 1, n) xw[i] = orz(), f[i] = i, siz[i] = 1, SUM ^= xw[i];
tot = 1;
L(i, 1, m) {
int u, v;
cin >> u >> v;
if(u > v) swap(u, v);
lk(u, v, 1);
}
L(t, 2, k) {
int fa;
cin >> fa, e[fa].emplace_back(t);
cin >> str[t] >> xu[t] >> xv[t];
}
dfs(1);
for(auto u : mp) if(u.second <= k) mark(1, 1, k, u.second, k, u.first);
dc(1, 1, k);
L(i, 1, k) ovo[ns[i]].emplace_back(i);
cout << sz(ovo) << '\n';
for(auto u : ovo) {
cout << sz(u.second) << ' ';
for(auto p : u.second) cout << p << ' ';
cout << '\n';
}
L(i, 1, k) e[i].clear();
}
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--) Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 40ms
memory: 160016kb
input:
2 15 11 8 6 11 1 6 6 9 6 8 1 2 1 5 9 10 2 5 1 add 3 11 1 add 2 3 3 add 5 8 4 add 5 11 3 add 7 10 1 add 6 10 3 add 3 10 1 remove 6 8 5 add 4 9 1 add 2 9 8 add 7 8 3 add 2 4 1 remove 6 9 10 remove 6 9 14 5 2 1 5 1 4 1 add 2 4 1 add 3 4 1 add 2 4 4 add 3 4 4 add 1 3 5 add 1 3 2 add 2 3 1 add 1 2 4 add ...
output:
7 3 1 7 11 5 2 3 4 5 8 1 15 2 10 13 2 6 12 1 14 1 9 5 1 13 2 3 11 6 5 6 7 8 10 12 2 1 14 3 2 4 9
result:
ok 2 test cases (2 test cases)
Test #2:
score: 0
Accepted
time: 78ms
memory: 159840kb
input:
100000 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 100000 test cases (100000 test cases)
Test #3:
score: 0
Accepted
time: 82ms
memory: 160024kb
input:
50000 1 2 0 1 2 1 1 2 1 2 1 1 2 1 1 0 1 1 0 1 1 0 2 2 0 1 add 1 2 2 2 0 1 add 1 2 1 1 0 1 1 0 1 1 0 1 2 0 2 2 0 1 add 1 2 1 1 0 1 2 0 1 1 0 1 1 0 1 2 1 1 2 1 1 0 1 1 0 1 1 0 2 2 1 1 2 1 remove 1 2 1 1 0 1 2 0 2 2 1 1 2 1 remove 1 2 1 2 0 1 2 0 1 1 0 2 2 1 1 2 1 remove 1 2 1 1 0 1 1 0 2 2 0 1 add 1 2...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 2 1 2 1 1 1 1...
result:
ok 50000 test cases (50000 test cases)
Test #4:
score: 0
Accepted
time: 88ms
memory: 159872kb
input:
20000 1 1 0 5 4 5 1 4 2 3 2 4 1 3 1 2 1 remove 1 4 1 remove 1 3 3 add 1 3 3 remove 1 4 1 1 0 4 3 1 1 2 1 add 2 3 2 remove 2 3 3 add 2 3 2 4 2 2 3 1 3 1 add 3 4 2 4 0 1 add 3 4 1 3 3 1 3 2 3 1 2 3 3 1 1 2 1 add 2 3 1 add 2 3 2 4 0 1 add 1 2 2 4 3 2 4 1 4 2 3 1 add 1 3 1 2 1 1 2 1 3 3 1 3 2 3 1 2 1 1 ...
output:
1 1 1 1 5 1 2 3 4 5 1 1 1 2 2 1 3 2 2 4 2 1 1 1 2 2 1 1 1 2 1 1 1 2 1 1 2 2 3 2 1 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 2 3 1 3 2 2 4 1 1 1 1 1 2 1 2 3 1 3 4 1 1 1 1 3 1 2 3 1 1 1 4 1 5 1 2 1 4 2 1 3 1 1 1 1 1 1 2 2 1 4 3 2 3 5 2 1 1 1 2 2 1 1 1 2 1 1 1 3 ...
result:
ok 20000 test cases (20000 test cases)
Test #5:
score: 0
Accepted
time: 71ms
memory: 159880kb
input:
10000 1 4 4 3 4 1 3 1 2 2 3 3 4 4 2 3 1 3 1 2 3 4 1 add 2 4 1 remove 3 4 8 6 9 1 5 3 5 2 3 1 3 3 4 4 5 1 2 2 5 4 6 1 remove 3 5 2 remove 3 4 3 remove 1 3 3 remove 1 3 1 add 5 6 1 add 3 6 1 add 2 6 1 1 0 2 5 9 3 4 4 5 1 4 1 3 1 5 3 5 2 5 1 2 2 3 1 remove 2 3 9 2 1 1 2 1 remove 1 2 2 add 1 2 1 remove ...
output:
1 1 1 2 1 3 2 1 2 1 8 1 2 3 4 5 6 7 8 1 1 1 1 2 1 2 2 6 2 4 5 6 7 8 3 1 3 9 7 1 1 1 7 2 3 8 2 5 6 1 2 1 4 1 9 3 1 4 1 2 2 1 3 4 1 1 2 3 5 1 4 1 2 1 1 1 5 1 3 1 2 1 1 1 5 1 4 5 1 4 1 3 1 5 2 2 6 1 1 4 1 5 1 1 3 2 3 7 3 4 6 8 2 1 2 1 1 3 1 1 1 3 1 2 2 2 2 3 3...
result:
ok 10000 test cases (10000 test cases)
Test #6:
score: 0
Accepted
time: 85ms
memory: 159860kb
input:
5000 18 10 13 4 7 2 5 1 8 8 10 4 6 9 10 3 10 8 9 1 7 2 4 3 9 2 9 2 3 1 remove 1 7 1 remove 4 7 1 add 6 8 4 add 5 6 2 add 4 9 3 add 2 6 6 remove 4 9 6 add 3 6 7 remove 2 9 10 add 6 10 9 add 7 9 8 add 3 6 8 add 1 9 1 remove 1 7 2 add 4 10 5 add 3 5 13 add 5 7 9 3 3 2 3 1 3 1 2 1 remove 2 3 1 remove 1 ...
output:
1 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 3 1 9 2 6 8 6 1 2 3 4 5 7 6 1 12 5 2 4 7 8 10 1 6 1 9 3 3 5 11 1 1 1 8 1 2 3 4 5 6 7 8 17 1 2 2 3 5 1 1 1 4 1 16 1 11 1 14 1 13 1 17 1 12 1 10 1 7 1 6 1 8 1 9 1 15 1 18 2 4 1 2 5 6 2 3 4 1 3 1 2 3 5 1 4 1 2 1 5 1 3 ...
result:
ok 5000 test cases (5000 test cases)
Test #7:
score: 0
Accepted
time: 84ms
memory: 160008kb
input:
2000 11 40 21 6 19 16 18 24 30 13 35 16 32 7 11 17 38 28 33 32 36 17 26 28 30 2 19 3 17 9 12 21 34 8 40 13 27 23 36 24 32 22 27 16 31 1 add 4 11 2 add 31 34 1 add 8 13 2 add 8 22 5 add 6 30 6 add 21 29 1 add 12 38 6 add 27 32 1 add 33 35 3 add 13 18 27 49 19 10 46 15 47 23 34 38 39 20 24 2 18 1 13 4...
output:
11 1 9 1 4 1 1 1 10 1 8 1 11 1 3 1 6 1 2 1 7 1 5 26 1 4 1 23 1 10 1 24 1 26 1 9 1 22 1 13 1 17 1 20 1 7 1 8 1 6 1 5 1 12 1 27 1 11 1 15 1 19 1 14 1 16 1 18 1 2 1 21 1 3 2 1 25 1 1 1 37 1 34 1 24 1 15 1 25 1 17 1 4 1 30 1 1 1 3 1 14 1 10 1 18 1 36 1 ...
result:
ok 2000 test cases (2000 test cases)
Test #8:
score: 0
Accepted
time: 95ms
memory: 159924kb
input:
1000 54 84 96 19 74 38 61 61 66 26 59 31 56 12 48 24 63 5 14 12 14 51 78 36 49 18 64 14 38 16 50 55 75 29 52 15 65 12 27 3 13 40 52 48 83 7 81 23 30 23 54 62 74 32 75 66 67 4 69 32 34 8 23 78 80 24 70 3 52 22 73 19 35 22 52 17 60 49 83 9 63 53 81 18 29 8 9 34 47 23 82 30 81 53 61 16 62 2 7 19 25 17 ...
output:
6 1 10 43 1 2 3 4 5 6 7 8 11 12 13 14 16 17 20 21 22 23 24 25 26 27 28 30 32 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 52 53 54 7 9 15 18 19 29 31 33 1 51 1 43 1 50 87 1 72 1 51 1 22 1 25 1 86 1 67 1 80 1 78 1 49 1 70 1 82 1 62 1 83 1 9 1 43 1 52 1 61 1 39 1 11 1 21 1 24...
result:
ok 1000 test cases (1000 test cases)
Test #9:
score: 0
Accepted
time: 91ms
memory: 160032kb
input:
500 92 109 51 59 76 18 43 28 63 11 75 63 106 44 59 39 49 34 37 53 75 16 36 50 101 41 60 22 23 89 101 30 88 85 92 72 102 3 44 81 90 30 85 23 31 62 83 51 63 77 78 53 92 58 95 37 97 72 99 68 88 59 78 32 104 68 102 40 62 26 30 101 109 55 94 31 98 25 80 55 56 38 106 53 56 23 91 5 97 4 92 2 92 21 36 38 73...
output:
89 1 11 1 6 1 68 1 62 1 45 1 80 1 85 1 19 1 47 1 27 1 29 1 48 2 1 13 1 69 1 5 1 28 1 76 1 49 1 91 1 2 1 34 1 30 1 55 1 24 1 70 1 73 1 38 1 86 1 83 1 57 1 78 1 37 1 20 1 71 1 87 1 21 1 4 1 26 1 54 1 90 1 36 2 17 22 1 75 1 84 1 61 1 41 1 92 1 81 1 65 1 ...
result:
ok 500 test cases (500 test cases)
Test #10:
score: 0
Accepted
time: 91ms
memory: 160132kb
input:
200 317 107 98 45 59 17 106 48 89 10 53 9 84 1 60 74 93 32 79 66 91 76 89 19 31 38 89 15 68 15 46 25 52 20 30 32 92 46 86 75 98 65 66 36 61 44 89 19 39 14 24 40 54 25 39 42 51 10 107 13 76 10 34 41 69 6 14 49 66 12 98 6 93 43 83 50 75 26 29 35 37 19 78 26 45 48 81 87 104 40 42 101 105 23 48 29 100 5...
output:
103 1 99 1 273 1 263 1 125 3 32 89 264 1 205 3 145 160 183 3 96 179 265 1 210 1 157 4 218 262 283 317 6 75 159 175 215 217 303 1 189 2 41 293 1 236 16 8 14 29 34 49 53 77 116 137 178 187 190 222 225 254 290 1 87 1 122 4 182 193 231 252 5 150 191 203 301 311 1 171 1 173 24 37 45...
result:
ok 200 test cases (200 test cases)
Test #11:
score: 0
Accepted
time: 103ms
memory: 160320kb
input:
100 121 451 775 4 424 238 297 74 370 59 244 17 182 151 421 104 277 149 154 135 381 289 451 177 257 69 79 255 315 108 351 42 266 79 117 47 365 105 350 124 393 226 260 11 101 203 279 93 174 316 352 144 332 111 404 44 333 195 237 43 72 70 112 29 446 5 36 31 262 367 370 252 260 10 212 57 423 84 129 10 2...
output:
16 1 74 4 35 57 96 117 1 50 11 21 23 29 60 84 89 90 93 95 104 121 1 115 7 17 18 48 49 86 91 119 1 107 2 78 111 4 70 79 94 120 19 1 3 9 11 20 30 34 38 43 45 46 59 69 71 76 80 81 99 116 2 92 98 4 39 40 63 114 51 2 4 5 6 7 8 10 12 13 14 15 16 19 24 26 27 28 32 33 36 37 41 42 44 47 51 52 53 ...
result:
ok 100 test cases (100 test cases)
Test #12:
score: 0
Accepted
time: 115ms
memory: 160568kb
input:
50 366 363 871 115 305 7 148 47 163 103 291 24 130 83 328 105 169 109 356 116 155 58 324 195 213 114 341 20 154 9 272 66 204 2 175 62 221 208 295 69 82 15 49 82 269 172 257 27 325 116 347 103 290 131 312 105 269 25 43 238 247 66 184 126 246 93 241 66 123 114 154 150 300 3 245 43 130 53 162 313 337 1...
output:
2 355 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...
result:
ok 50 test cases (50 test cases)
Test #13:
score: 0
Accepted
time: 112ms
memory: 161216kb
input:
20 3609 4008 837 2049 2213 500 2782 981 1104 2910 3700 2996 3942 177 2513 1166 3745 1394 2249 203 3592 638 3271 616 1096 805 3419 797 2862 587 2798 1880 2098 786 878 2399 2499 532 2567 2748 3963 1934 3353 506 1599 71 2935 512 3177 62 3844 1666 3590 664 3581 283 3555 579 1354 1601 2363 412 1206 1615 ...
output:
3609 1 219 1 663 1 1347 1 2746 1 2512 1 1931 1 2750 1 971 1 2976 1 2398 1 2690 1 1414 1 56 1 3325 1 2155 1 337 1 1380 1 2095 1 73 1 1902 1 402 1 2004 1 2778 1 3572 1 287 1 1742 1 69 1 422 1 557 1 1274 1 436 1 1271 1 2978 1 666 1 300 1 2791 1 1714 1 1382 1 2870 ...
result:
ok 20 test cases (20 test cases)
Test #14:
score: 0
Accepted
time: 108ms
memory: 162332kb
input:
10 9915 1990 542 778 1095 530 538 967 1940 57 1069 669 1767 326 1155 508 1531 41 1676 639 1499 712 1271 979 1376 525 1350 648 1659 653 874 984 1767 175 774 1004 1477 304 657 535 568 1126 1597 201 780 681 989 1090 1189 824 1937 1124 1609 213 1238 984 989 446 870 868 955 480 1644 314 1045 181 1308 103...
output:
9912 1 171 1 6984 1 8591 1 670 1 9259 1 6757 1 8508 1 336 1 8407 1 4922 1 9333 1 5199 1 4439 1 1629 1 4365 1 3593 1 7216 1 7440 1 3140 1 5974 1 3366 1 2508 1 6680 1 1771 1 4259 1 8573 1 4780 1 9545 1 6034 1 2502 1 2576 1 4665 1 5114 1 5651 1 9605 1 3394 1 597 1 8...
result:
ok 10 test cases (10 test cases)
Test #15:
score: 0
Accepted
time: 99ms
memory: 163400kb
input:
5 2967 17745 19851 10948 16107 4858 14846 3325 7313 2397 4344 10335 11714 1484 1580 3502 12410 12342 16272 9921 11976 6289 6519 9732 15873 960 16079 1993 2798 13211 17278 682 13575 2820 10492 5601 7665 557 5400 650 3869 2979 10428 3159 11311 6899 13508 8963 9837 9977 15458 462 2338 323 12439 7351 13...
output:
850 2 391 2911 3 279 565 2534 1 2800 1 1934 1 2932 2 1014 1759 12 124 200 282 335 344 425 485 665 954 1588 1858 2115 2 1182 1503 4 961 1464 1791 2134 1 2630 1 1519 2 2316 2961 3 701 2036 2293 1 2742 9 113 143 411 741 890 978 1981 2247 2897 2 2454 2649 2 1449 2068 1 2542 1 2235 1 1...
result:
ok 5 test cases (5 test cases)
Test #16:
score: 0
Accepted
time: 153ms
memory: 167780kb
input:
2 44670 24444 44531 2231 13814 3020 7883 8780 13081 14706 18191 15483 15645 736 2335 4181 8023 16113 16128 1852 2346 6807 18822 2729 3872 5806 12065 1365 22933 5238 20511 8763 9658 12271 17543 6159 21137 9149 22354 9572 19086 6656 13372 14682 17845 8766 13103 561 10225 146 2015 14376 16911 11500 168...
output:
1932 2 14842 29972 2 40520 40724 5 5346 7151 20192 23668 27842 1 33272 3 811 864 11293 1 19874 1 43465 13 2827 5104 27763 27907 28114 28134 31511 32467 33885 37206 38414 42031 42834 1 38897 1 43933 1 38644 2 22509 23335 1 27886 1 25706 2 15894 19899 1 44043 2 29530 30778 1 28583 1 ...
result:
ok 2 test cases (2 test cases)
Test #17:
score: 0
Accepted
time: 174ms
memory: 173552kb
input:
1 60780 74010 60615 5913 38347 61614 63118 30437 50526 29834 34044 23551 28539 7992 31743 25554 64954 32405 55326 2977 59970 65356 66572 16822 28165 18082 48449 13853 16034 9923 16249 23496 44883 10095 12189 24327 51156 14432 52807 12478 48435 177 33873 34488 35796 45947 61183 15625 42990 5138 55573...
output:
33931 1 24722 2 37113 59547 2 22091 36481 2 47018 51900 1 54499 2 23779 23942 1 39254 1 59429 1 14826 2 16079 33160 1 53280 1 59066 1 47462 1 39610 3 21532 26802 58344 2 38169 57279 3 25197 27242 52521 2 14591 52269 1 17267 1 46339 1 11009 1 40896 1 51306 1 42003 4 7986 11151...
result:
ok 1 test cases (1 test case)
Test #18:
score: 0
Accepted
time: 279ms
memory: 180256kb
input:
1 100000 100000 100000 82293 84993 13580 99080 75196 77296 37184 55180 20180 39717 40787 90213 2609 10289 42228 78352 34697 75497 37335 54521 30130 96372 38307 83217 47643 59250 44707 61880 61497 87838 21320 59185 6692 41427 25040 58136 1093 94374 15844 83475 39458 61209 19277 71639 12487 50785 6585...
output:
36649 19 6623 11040 12988 16125 24000 29190 38617 45517 46763 47997 48336 48439 49830 50988 51362 58022 61564 65459 97448 1 71786 1 21973 1 91238 1 94495 1 89946 1 67929 1 54291 1 40661 1 33295 1 39266 1 48895 1 33365 3 50914 56189 84812 1 89785 1 75395 2 46371 69495 1 80736 1 6233...
result:
ok 1 test cases (1 test case)