QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#293025 | #4891. 树上的孤独 | zyc070419 | 0 | 851ms | 291748kb | C++14 | 5.9kb | 2023-12-28 20:13:44 | 2023-12-28 20:13:45 |
Judging History
answer
#include <bits/stdc++.h>
#define debug() puts("qwq"), exit(0)
#define INF 1e9
using namespace std;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
inline int read() {
char ch = getchar(); int x = 0;
while (!isdigit(ch)) {ch = getchar();}
while (isdigit(ch)) {x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
return x;
}
struct node {
int ls, rs, sum;
}t[N * 2 * 2 * 20];
struct Node {
int opt, x, y, p, q;
}Q[M];
int n, m, T, a[N], b[25], c[25], o[N + M + 25], cnt, depth[N], mx, mem[M][20], lst, dis[25][25];
int root[N], tot, in[N];
int mn[N + M + 25], vis[N + M + 25], sz[N], son[N], id[N], pos[N], num, fa[N], top[N];
vector<int> g[N], G[25], vec[N], to[N], col[N + M + 25], now;
void dfs1(int x, int pa, int d) {
depth[x] = d; fa[x] = pa; sz[x] = 1; mx = max(mx, d);
for (auto y : g[x]) {
if (y == pa) continue;
dfs1(y, x, d + 1);
sz[x] += sz[y];
if (sz[y] > sz[son[x]]) son[x] = y;
}
}
void dfs2(int x, int anc) {
top[x] = anc; id[x] = ++num; pos[num] = x;
if (son[x]) dfs2(son[x], anc);
for (auto y : g[x]) {
if (y == fa[x] || y == son[x]) continue;
dfs2(y, y);
}
}
inline void clear(int x) {for (int i = id[x]; i < id[x] + sz[x]; ++i) mn[a[pos[i]]] = INF;}
inline void updat(int x) {for (int i = id[x]; i < id[x] + sz[x]; ++i) mn[a[pos[i]]] = min(mn[a[pos[i]]], depth[pos[i]]);}
void dfs3(int x) {
for (auto y : g[x]) {
if (y == fa[x] || y == son[x]) continue;
dfs3(y); clear(y);
}
if (son[x]) dfs3(son[x]);
mn[a[x]] = depth[a[x]];
for (auto y : g[x]) {
if (y == fa[x] || y == son[x]) continue;
updat(y);
}
for (auto ID : vec[x])
for (int i = 1; i <= m; ++i)
mem[ID][i - 1] = mn[mem[ID][i - 1]];
}
void dfs4(int x, int pa, int anc) {
for (auto y : G[x]) {
if (y == pa) continue;
dis[anc][y] = dis[anc][x] + 1;
dfs4(y, x, anc);
}
}
inline int LCA(int x, int y) {
int fx = top[x], fy = top[y];
while (fx != fy) {
if (depth[fx] < depth[fy]) swap(fx, fy), swap(x, y);
x = fa[fx]; fx = top[x];
}
if (id[x] > id[y]) swap(x, y);
return x;
}
void update(int &rt, int l, int r, int x, int v) {
if (!rt) rt = ++tot;
if (l == r) return t[rt].sum += v, void();
int mid = (l + r) >> 1;
if (x <= mid) update(t[rt].ls, l, mid, x, v);
else update(t[rt].rs, mid + 1, r, x, v);
t[rt].sum = t[t[rt].ls].sum + t[t[rt].rs].sum;
}
void dfs5(int x, int pa) {
// printf("{%d}\n", x);
for (auto y : to[x]) {
// if (x == 3) debug();
dfs5(y, x);
in[x] = min(in[x], in[y]);
}
// printf("in[%d] = %d\n", x, in[x]);
update(root[x], 1, mx, in[x], 1);
if (pa) update(root[pa], 1, mx, in[x], -1);
}
int merge(int x, int y, int l, int r) {
if (!x || !y) return x | y;
if (l == r) {
int z = ++tot;
t[z].sum = t[x].sum + t[y].sum;
return z;
}
int mid = (l + r) >> 1, z = ++tot;
t[z].ls = merge(t[x].ls, t[y].ls, l, mid);
t[z].rs = merge(t[x].rs, t[y].rs, mid + 1, r);
t[z].sum = t[t[z].ls].sum + t[t[z].rs].sum;
return z;
}
int query(int rt, int l, int r, int lim) {
if (!rt) return 0;
if (lim < l) return 0;
if (r <= lim) return t[rt].sum;
int mid = (l + r) >> 1;
if (mid <= lim) return t[t[rt].ls].sum + query(t[rt].rs, mid + 1, r, lim);
else return query(t[rt].ls, l, mid, lim);
}
void dfs6(int x) {
for (auto y : g[x]) {
if (y == fa[x]) continue;
dfs6(y);
root[x] = merge(root[x], root[y], 1, mx);
}
}
int main() {
m = read(); n = read(); T = read();
for (int i = 1, x, y; i < m; ++i) {
x = read(); y = read();
G[x].push_back(y);
G[y].push_back(x);
}
for (int i = 1, x, y; i < n; ++i) {
x = read(); y = read();
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 1; i <= m; ++i) o[++cnt] = b[i] = read();
for (int i = 1; i <= n; ++i) o[++cnt] = a[i] = read();
for (int i = 1; i <= T; ++i) {
Q[i].opt = read();
if (Q[i].opt == 1) {
Q[i].x = read(); Q[i].y = read();
Q[i].p = read(); Q[i].q = read();
}else {
Q[i].x = read();
Q[i].y = o[++cnt] = read();
}
}
sort(o + 1, o + 1 + cnt); cnt = unique(o + 1, o + 1 + cnt) - o - 1;
for (int i = 1; i <= m; ++i) b[i] = lower_bound(o + 1, o + 1 + cnt, b[i]) - o;
for (int i = 1; i <= n; ++i) a[i] = lower_bound(o + 1, o + 1 + cnt, a[i]) - o;
for (int i = 1; i <= T; ++i)
if (Q[i].opt == 2) Q[i].y = lower_bound(o + 1, o + 1 + cnt, Q[i].y) - o;
for (int i = 1; i <= cnt; ++i) mn[i] = INF;
for (int i = 1; i <= m; ++i) c[i] = b[i];
for (int i = 1; i <= T; ++i) {
if (Q[i].opt == 1) {
for (int j = 0; j < m; ++j) mem[i][j] = c[j + 1];
vec[Q[i].y].push_back(i);
}
else c[Q[i].x] = Q[i].y;
}
dfs1(1, 1, 1); dfs2(1, 1); dfs3(1);
for (int i = 1; i <= m; ++i) dfs4(i, i, i);
// debug();
for (int i = 1; i <= n; ++i) col[a[i]].push_back(i), in[i] = INF;
for (int ID = 1, cur; ID <= cnt; ++ID) {
// printf("*[%d] : \n", o[ID]);
if (col[ID].empty()) continue;
now.push_back(1);
for (auto x : col[ID]) now.push_back(x), in[x] = depth[x];
sort(now.begin(), now.end(), [&](int xx, int yy) {return id[xx] < id[yy];});
cur = now.size();
for (int i = 1; i < cur; ++i) now.push_back(LCA(now[i - 1], now[i]));
sort(now.begin(), now.end(), [&](int xx, int yy) {return id[xx] < id[yy];});
now.erase(unique(now.begin(), now.end()), now.end());
for (int i = 1; i < (int)now.size(); ++i) to[LCA(now[i - 1], now[i])].push_back(now[i]);
dfs5(1, 0);
for (auto x : now) to[x].clear(), in[x] = INF;
now.clear();
}
// debug();
dfs6(1);
for (int ID = 1, x, y, p, q; ID <= T; ++ID) {
if (Q[ID].opt == 1) {
x = Q[ID].x, y = Q[ID].y, p = Q[ID].p ^ lst, q = Q[ID].q ^ lst;
lst = query(root[y], 1, mx, depth[y] + q);
// printf("{%d}\n", lst);
for (int i = 1; i <= m; ++i) {
if (dis[x][i] > p) continue;
if (vis[b[i]] == ID) continue;
if (depth[y] + q >= mem[ID][i - 1]) continue;
lst++; vis[b[i]] = ID;
}
printf("%d\n", lst);
}
else b[Q[ID].x] = Q[ID].y;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 48192kb
input:
20 2000 2000 8 15 8 13 14 8 14 7 12 14 12 1 9 13 9 4 5 9 5 10 2 5 2 19 6 19 6 16 11 7 11 20 18 2 18 17 3 6 1395 1783 1395 1735 1735 457 457 739 739 438 438 101 101 441 441 1879 1879 1238 1238 501 501 1732 1732 1910 1910 2000 2000 834 834 917 917 111 111 780 780 1966 1966 1604 1604 623 623 1748 1748 ...
output:
107 104 20 55 20 55 195 25 79 20 21 200 73 88 146 30 68 68 52 35 29 23 40 79 67 109 45 200 41 87 97 39 87 36 201 103 32 63 27 36 73 60 39 20 118 161 23 21 32 90 53 108 26 77 177 84 37 150 143 25 141 31 109 142 121 68 37 64 18 40 56 48 54 30 61 157 111 132 144 202 25 80 81 40 82 25 28 37 160 51 73 60...
result:
wrong answer 1st numbers differ - expected: '105', found: '107'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 576ms
memory: 218028kb
input:
20 200000 500000 8 18 8 4 2 4 2 14 13 4 13 16 6 4 6 3 1 4 1 17 15 6 15 19 7 17 7 11 5 14 5 10 20 7 12 15 9 8 165302 77239 165302 198189 165302 180850 165302 192738 165302 173589 165302 194087 165302 191990 165302 167370 165302 101092 165302 92553 165302 163654 165302 122381 165302 152105 165302 1919...
output:
16 17598 3912 3437 21 537 5152 11358 21 7352 21 18327 15797 6642 533 1199 6125 1884 6241 681 16739 13230 1616 5462 6074 2403 6278 21 21 297 3511 1822 1251 1056 17804 4668 5536 4649 4561 21 262 2703 21 4624 8564 4032 21 13504 5653 2071 3502 4881 5835 802 2072 1496 13238 2593 938 16774 21 17626 353 21...
result:
wrong answer 1st numbers differ - expected: '2', found: '16'
Subtask #3:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 200ms
memory: 124320kb
input:
20 100000 100000 16 12 16 20 6 12 6 18 2 16 2 8 5 20 5 13 3 6 3 11 19 11 19 17 9 12 9 15 4 15 4 7 10 5 14 15 14 1 85812 94626 85812 91172 91172 93788 93788 96567 96567 75524 75524 23275 23275 98340 98340 81608 81608 91480 91480 75108 75108 56605 56605 93317 93317 41617 41617 77160 77160 727 727 7559...
output:
2568 624 8323 8985 3561 9182 647 301 2483 7323 2682 1170 1401 1271 8231 4408 109 2696 640 4479 3165 9184 21 8983 2108 9950 8016 9944 21 5044 87 2038 1896 21 1292 2191 355 1052 9390 3477 7730 1970 2755 1303 2331 715 21 563 21 448 716 2333 462 23 39 1440 2321 693 2458 21 2334 714 9999 21 196 1384 8933...
result:
wrong answer 2nd numbers differ - expected: '612', found: '624'
Subtask #4:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 554ms
memory: 236456kb
input:
1 200000 500000 189127 137023 189127 199761 199761 160701 160701 130639 130639 190908 190908 176819 176819 193363 193363 188021 188021 182446 182446 186028 186028 198828 198828 190792 190792 155378 155378 189428 189428 177276 177276 146159 146159 175923 175923 188073 188073 182206 182206 131072 1310...
output:
3782 1773 771 7328 18160 19394 1952 2 5498 2 2859 3368 7393 5131 5706 2 6001 19866 2 5123 2 12549 1497 4837 7770 16333 18175 5926 17983 19707 3821 17709 17094 4226 3822 576 5637 3660 4987 15686 2 18774 29 5068 16606 2276 16601 4544 598 845 19976 7054 882 164 2744 1683 6746 5091 1632 5136 2931 2778 1...
result:
wrong answer 57th numbers differ - expected: '6747', found: '6746'
Subtask #5:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 851ms
memory: 291748kb
input:
20 200000 1000000 13 10 13 5 19 5 19 20 15 10 15 6 12 6 12 3 8 10 8 2 1 20 1 11 14 10 14 16 18 3 18 7 4 3 9 10 9 17 194055 154514 194055 148156 148156 115271 115271 198116 198116 179433 179433 171975 171975 196600 196600 167194 167194 185078 185078 191409 191409 163496 163496 178243 178243 154093 15...
output:
464 5820 10120 7668 4872 19470 3581 16033 2850 7551 1131 9926 18495 497 11876 2133 9851 7588 7301 111 1850 7393 3362 6058 19489 16460 6224 1744 5925 5605 3820 1930 718 3319 2715 19890 5621 627 771 1319 15995 2986 1671 14680 5222 2653 118 1915 3266 1934 14610 4592 7233 5902 11034 4405 7471 9764 19633...
result:
wrong answer 1st numbers differ - expected: '459', found: '464'