QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#449454 | #5358. 宝石游戏 | Rikku_eq | 0 | 1727ms | 24916kb | C++14 | 3.3kb | 2024-06-21 10:37:16 | 2024-06-21 10:37:16 |
Judging History
answer
#include <bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
int n, m, c[N];
int dep[N], len[N], son[N], tI[N], tO[N], tmr;
vector <int> to[N];
ll buf[N*2], buf2[N*2], *f[N], *suf[N], *cur=buf, *cur2=buf2;
ll tg[N];
int B, st[N], idB[N];
ll ans[N];
vector <int> vec[N];
struct Qry { int op, x, v; } q[N];
void dfs_son (int u, int fa)
{
for (int i=0; i<(int)to[u].size(); i++) {
int v=to[u][i];
if (v==fa) { continue; }
dfs_son(v, u);
if (len[v]>len[son[u]]) { son[u]=v; }
}
len[u]=len[son[u]]+1;
}
void dfs_f (int u, int fa)
{
tI[u]=++tmr; dep[u]=dep[fa]+1;
if (son[u]) {
f[son[u]]=f[u]+1;
suf[son[u]]=suf[u]+1;
dfs_f(son[u], u);
}
for (int i=0; i<(int)to[u].size(); i++) {
int v=to[u][i];
if (v==fa || v==son[u]) { continue; }
f[v]=cur; cur+=(len[v]+1);
suf[v]=cur2; cur2+=(len[v]+1);
dfs_f(v, u);
}
tO[u]=tmr;
}
bool up (int u, int v) { return tI[u]<=tI[v] && tO[v]<=tO[u]; }
void cal (int u, int fa, int idb)
{
if (son[u]) {
cal(son[u], u, idb);
}
f[u][0]=c[u];
suf[u][0]=(len[u]==0 ? f[u][0] : (suf[u][1]^f[u][0]));
for (int i=0; i<(int)to[u].size(); i++) {
int v=to[u][i];
if (v==fa || v==son[u]) { continue; }
cal(v, u, idb);
for (int j=0; j<=len[v]; j++) {
tg[j+1]=(f[u][j+1]^(f[u][j+1]+f[v][j]));
f[u][j+1]+=f[v][j];
}
tg[0]=0;
for (int j=len[v]+1; j>=0; j--) {
if (j<=len[v]) { tg[j]^=tg[j+1]; }
suf[u][j]^=tg[j];
}
}
for (int i=0; i<(int)vec[u].size(); i++) {
int qid=vec[u][i], L=q[qid].v;
if (L>=len[u]) { ans[qid]=suf[u][0]; }
else { ans[qid]=(suf[u][0]^suf[u][L+1]); }
for (int j=st[idb]; j<qid; j++) {
int x=q[j].x, v=q[j].v;
if (up(u, x) && dep[x]-dep[u]<=L) {
ans[qid]^=(f[u][dep[x]-dep[u]]^(f[u][dep[x]-dep[u]]-c[x]+v));
}
}
}
}
void solve ()
{
len[0]=-1; dfs_son(1, 0);
f[1]=cur; cur+=len[1];
suf[1]=cur2; cur2+=len[1];
dfs_f(1, 0);
for (int i=1; i<=m; i=st[idB[i]+1]) {
for (int u=1; u<=n; u++) { vec[u].clear(); }
fill(buf, cur, 0);
fill(buf2, cur2, 0);
for (int j=i; j<st[idB[i]+1]; j++) {
if (q[j].op==2) { vec[q[j].x].push_back(j); }
}
cal(1, 0, idB[i]);
for (int j=i; j<st[idB[i]+1]; j++) {
if (q[j].op==1) { c[q[j].x]=q[j].v; }
}
}
for (int i=1; i<=m; i++) if (q[i].op==2) { printf("%lld\n", ans[i]); }
}
int main ()
{
// freopen("0test.in", "r", stdin);
// freopen("0test.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i=1; i<=n; i++) { scanf("%d", &c[i]); }
for (int i=1; i<n; i++) {
int u, v; scanf("%d %d", &u, &v);
to[u].push_back(v);
to[v].push_back(u);
}
for (int t=1; t<=m; t++) {
scanf("%d %d %d", &q[t].op, &q[t].x, &q[t].v);
}
B=ceil(sqrt(m));
for (int i=1; i<=m; i++) {
idB[i]=((i-1)/B)+1;
if (!st[idB[i]]) { st[idB[i]]=i; }
}
st[idB[m]+1]=m+1;
solve();
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: 2ms
memory: 12168kb
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: 0
Wrong Answer
time: 0ms
memory: 11440kb
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:
13348898220 15233413294 741310833 9805924300 1453416743 3788645358 14533212155 14801769751 13332251740 16109767583 2373615391 13107657774 13673465336 13860053603 14648556653 14343498490 13477375301 13907249441 12912042639 2587887866 12249404624 11860790531 10729779648 14456420865 8927957994 42616220...
result:
wrong answer 3rd lines differ - expected: '1022133674', found: '741310833'
Subtask #2:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 1618ms
memory: 24916kb
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 2435829606 1639080466 1086525690 4252299227 862471314 806170012 960496538 1470813685 517621825 38523298...
result:
wrong answer 67th lines differ - expected: '243230910', found: '4503593'
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 1727ms
memory: 24660kb
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:
4014146821 2718560828 1298976569 559452402 3944231402 613142938 576834001 255379182 280218472 121213840 2168405789 1445110982 1529231542 764634671 5108399241 4138140954 1976870585 6804287641 1698466896 1997484355 2986905666 2079137741 1376913446 89904194 1865025508 8415508119 1397814715 902893842 13...
result:
wrong answer 6th lines differ - expected: '7231839253', found: '613142938'
Subtask #4:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 1636ms
memory: 24220kb
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:
11993349061 8780326633 12098734542 3054518456 11055891816 9204753253 10743559784 9147254560 10509780664 8701339065 4802112670 9364381167 15266918820 16950603611 14438458792 11278664545 11644332420 10329713597 10849259251 12450971260 12585306107 11154701241 11949273205 12838160302 15858783097 1136868...
result:
wrong answer 5th lines differ - expected: '11132272208', found: '11055891816'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%