QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89566 | #5358. 宝石游戏 | Scintilla | 0 | 2082ms | 29672kb | C++14 | 3.4kb | 2023-03-20 16:26:43 | 2023-03-20 16:26:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
using pii = pair <int, int>;
const int N = 2e5 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int n, m, B, a[N], dfn[N], dn, sz[N], mx[N], mson[N], dep[N], ans[N], l, r;
int pool[N << 1], *fcur, *f[N], *gcur, *g[N], ca[N], cf[N];
vector <int> e[N];
vector <int> qry[N];
struct node {
int op, u, k;
} o[N];
void dfs0(int u, int fa) {
dfn[u] = ++ dn, sz[u] = 1;
for (int v : e[u]) if (v != fa) {
dep[v] = dep[u] + 1, dfs0(v, u), sz[u] += sz[v];
if (mx[v] + 1 > mx[u]) mx[u] = mx[v] + 1, mson[u] = v;
}
}
void dfs1(int u, int fa) {
f[u] = ++ fcur, g[u] = ++ gcur;
if (mson[u]) dfs1(mson[u], u);
for (int v : e[u]) if (v != fa && v != mson[u]) dfs1(v, u);
}
bool in(int u, int v) {
return dfn[u] <= dfn[v] && dfn[v] < dfn[u] + sz[u];
}
void dfs2(int u, int fa) {
f[u][0] = g[u][0] = a[u];
if (mson[u]) dfs2(mson[u], u), g[u][0] ^= g[u][1];
for (int v : e[u]) if (v != fa && v != mson[u]) {
dfs2(v, u);
rep(i, 0, mx[v]) f[u][i + 1] += f[v][i];
g[u][mx[v] + 1] = f[u][mx[v] + 1];
if (mx[v] + 1 < mx[u]) g[u][mx[v] + 1] ^= g[u][mx[v] + 2];
drep(i, mx[v], 0) g[u][i] = g[u][i + 1] ^ f[u][i];
}
// cout << "------- u = " << u << endl;
// pa(f[u], 0, mx[u]);
// pa(g[u], 0, mx[u]);
for (int i : qry[u]) {
// pv(i);
int res = g[u][0], lim = o[i].k;
// cout << "lim, mx[u] = " << lim << ' ' << mx[u] << endl;
// pv(res);
if (lim < mx[u]) res ^= g[u][lim + 1];
// pv(res);
for (int j = l, v, d; j < i; ++ j) {
if (o[j].op == 1 && in(u, v = o[j].u) && (d = dep[v] - dep[u]) <= lim) {
if (!~ca[v]) ca[v] = a[v];
if (!~cf[d]) cf[d] = f[u][d];
// cout << "d, cf[d] = " << d << ' ' << cf[d] << endl;
// pv(ca[v]);
res ^= cf[d], cf[d] -= ca[v];
ca[v] = o[j].k;
cf[d] += ca[v], res ^= cf[d];
// pv(cf[d]);
}
}
for (int j = l, v, d; j < i; ++ j) {
if (o[j].op == 1 && in(u, v = o[j].u) && (d = dep[v] - dep[u]) <= lim) ca[v] = cf[d] = -1;
}
ans[i] = res;
}
}
int main() {
n = read(), m = read(), B = sqrt(m);
rep(i, 0, n) ca[i] = cf[i] = -1;
rep(i, 1, n) a[i] = read();
rep(i, 1, n - 1) {
int u = read(), v = read();
e[u].emplace_back(v);
e[v].emplace_back(u);
}
dfs0(1, 0);
fcur = pool, gcur = pool + 2 * n;
dfs1(1, 0);
// pa(mson, 1, n);
rep(i, 1, m) o[i].op = read(), o[i].u = read(), o[i].k = read();
for (l = 1, r; l <= m; l = r + 1) {
r = min(l + B - 1, m);
// cout << "---------- l, r = " << l << ' ' << r << " ----------\n";
rep(i, l, r) if (o[i].op == 2) qry[o[i].u].emplace_back(i);
dfs2(1, 0);
rep(i, l, r) {
if (o[i].op == 1) a[o[i].u] = o[i].k;
else qry[o[i].u].clear();
}
}
rep(i, 1, m) if (o[i].op == 2) printf("%d\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 1ms
memory: 23908kb
input:
7 5 1 2 3 4 5 6 7 3 1 2 4 3 7 6 7 5 4 4 1 2 1 1 2 4 0 2 7 2 1 6 0 2 7 1
output:
6 4 1 7
result:
ok 4 lines
Test #2:
score: -7
Wrong Answer
time: 9ms
memory: 21936kb
input:
1000 1000 168301431 651266519 181230331 997564131 922958564 240686472 828844423 997226083 101127334 549182223 815802272 962217487 872007143 308493550 875871642 388491137 726655288 632336322 36483715 91926885 973887125 969715766 903583959 709995095 551483747 454472802 645719871 210282402 246763026 76...
output:
463996332 -1946455890 1022133674 1215989708 1260198611 -506321938 1275059289 1699052275 273550476 -369663939 -1994651746 1702774112 1342199726 1084021643 1763654765 1707686856 1768504433 1173342503 1250167546 -1707079430 1419994572 137854869 -360243130 -1594822034 -299827756 -2029833898 -306645529 3...
result:
wrong answer 1st lines differ - expected: '13348898220', found: '463996332'
Subtask #2:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 2082ms
memory: 29672kb
input:
100000 100000 405003099 610837546 348589233 875137317 862931320 731758484 582603782 989991623 184749683 961137536 740146957 148627391 849777698 445045421 119699522 266347287 445197848 974544475 91680144 328247730 665144499 422991113 252383902 770011580 393442268 470439648 712319066 315986988 4789186...
output:
981730896 747543671 48940353 1063131294 1664022464 2108439828 1676415478 1758820567 841425155 1487919939 550289640 502601409 857432062 545225207 534191912 1529755415 1934872270 184068092 530775075 -1859137690 1639080466 1086525690 -42668069 862471314 806170012 960496538 1470813685 517621825 38523298...
result:
wrong answer 20th lines differ - expected: '2435829606', found: '-1859137690'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 1869ms
memory: 27684kb
input:
100000 100000 391636738 188947351 607003168 699971181 102753269 291890533 830830147 76057458 623517854 58958317 449828617 773557323 669394342 548355126 601286710 238603435 809091745 772998770 894693501 564199529 196062134 2803096 781469712 870912328 138245421 273392139 476952377 787775209 401014779 ...
output:
-280820475 -1576406468 1298976569 559452402 -350735894 -1358095339 -77901933 -1406000065 -718184472 121213840 -2126561507 1445110982 1732950814 -190193555 -381584693 -156826342 1976870585 1327869233 1208369754 232829949 -1393405117 -1788733285 -1395751970 296851124 1177782314 -794328901 1397814715 1...
result:
wrong answer 1st lines differ - expected: '4014146821', found: '-280820475'
Subtask #4:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 2065ms
memory: 29024kb
input:
100000 100000 620733757 384382313 514191349 902009280 482178057 905939364 286556695 762555921 287205978 88334200 437152915 320217018 981790168 254780145 881516456 779810222 814317342 292303220 272120273 65511383 98150102 177581894 12582058 656218139 789187030 442791738 134622788 62465827 954191430 1...
output:
-891552827 190392041 -786167346 -1240448840 -1752629680 995747511 -1458628839 676652409 706285660 156738712 507145374 1545093149 -1167995994 -703964829 2046020913 -1044966743 -1458134065 1344901567 -280811333 938152113 -641729031 182888245 1450319270 -250591644 -2032490117 -463318500 -45734064 -1820...
result:
wrong answer 1st lines differ - expected: '11993349061', found: '-891552827'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%