QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793084 | #5297. 糖果公园 | gzy | 0 | 1360ms | 28736kb | C++14 | 2.6kb | 2024-11-29 16:35:33 | 2024-11-29 16:35:34 |
Judging History
answer
#include<bits/stdc++.h>
#define pb emplace_back
#define mn(a, b) (dfn[a] < dfn[b] ? a : b)
using namespace std;
using ll = long long;
using db = double;
constexpr int MAXSIZE = 1 << 20;
char buf[MAXSIZE], *p1, *p2;
#define gc() getchar()//(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? EOF : *p1++)
int rd() {int x = 0, f = 1;char c = gc();while (!isdigit(c)) {if (c == '-') f = -1;c = gc();}while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();return x * f;}
const int N = 1e5 + 7;
int i, j, k, n, m, a, b, B;
int v[N], w[N], c[N], dep[N];
int st[N], sz, bl[N], bk, q;
int f[20][N], id, dfn[N], ft[N];
int cnt[N], vis[N];
vector<int> d[N];
struct qry {
int x, y, t, id;
bool operator < (const qry&z) const {return bl[x] == bl[z.x] ? (bl[y] == bl[z.y] ? t < z.t : bl[y] < bl[z.y]) : bl[x] < bl[z.x];}
} qr[N], ch[N];
int Qr, Ch;
ll res, ans[N];
void dfs(int a, int fa) {
int k = sz;
f[0][dfn[a] = ++id] = fa;
dep[a] = dep[ft[a] = fa] + 1;
for(int b : d[a]) if(b != fa) {
dfs(b, a);
if(sz - k > B) {
++bk;
while(sz != k) bl[st[sz--]] = bk;
}
}
st[++sz] = a;
}
int lca(int x, int y) {
if(x == y) return x;
if((x = dfn[x]) > (y = dfn[y])) swap(x, y);
int k = __lg(y - x++);
return mn(f[k][x], f[k][y-(1<<k)+1]);
}
void ck(int x) {
if(vis[x]) res -= w[cnt[c[x]]--] * v[c[x]];
else res += w[++cnt[c[x]]] * v[c[x]];
vis[x] ^= 1;
}
void upd(int x, int y) {
while(x != y) {
if(dep[x] < dep[y]) swap(x, y);
ck(x), x = ft[x];
}
}
void add(qry&k) {
int x = k.x, y = k.y;
if(vis[x]) ck(x), swap(k.y, c[x]), ck(x);
else swap(k.y, c[x]);
}
signed main() {
scanf("%d%d%d", &n, &m, &q);
B = pow(n, 0.666);
for(i = 1; i <= m; i++) scanf("%d", &v[i]);
for(i = 1; i <= n; i++) scanf("%d", &w[i]);
for(i = 1; i < n; i++) {
scanf("%d%d", &a, &b);
d[a].pb(b), d[b].pb(a);
}
for(i = 1; i <= n; i++) scanf("%d", &c[i]);
dfs(1, 0);
while(sz) bl[st[sz--]] = bk;
for(j = 1; j <= __lg(n); j++) for(i = 1; i + (1 << j) - 1 <= n; i++)
f[j][i] = mn(f[j-1][i], f[j-1][i+(1<<j-1)]);
for(i = 1; i <= q; i++) {
int o, x, y;
scanf("%d%d%d", &o, &x, &y);
if(o) {
++Qr, qr[Qr] = {x, y, Ch, Qr};
} else ch[++Ch] = {x, y, 0, 0};
}
sort(qr + 1, qr + 1 + Qr);
int X = 1, Y = 1, T = 0;
ck(1);
for(i = 1; i <= Qr; i++) {
int x = qr[i].x, y = qr[i].y, t = qr[i].t;
upd(x, X), upd(y, Y);
ck(lca(x, y)), ck(lca(X, Y));
X = x, Y = y;
while(T < t) add(ch[++T]);
while(T > t) add(ch[T--]);
ans[qr[i].id] = res;
}
for(i = 1; i <= Qr; i++) printf("%lld\n", ans[i]);
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14396kb
input:
20 20 20 338985 290791 463601 487134 164037 217966 634037 150123 864209 974801 42241 909963 920357 443745 134001 852157 115722 364223 450033 259781 963481 938865 915101 822609 811713 768863 730441 590323 563935 559238 483185 478333 476461 431631 360547 123470 103899 93068 51575 31346 19 11 19 18 19 ...
output:
683555603 41116812 -2381491117 -1427070175 -1874368033 -1007110878 -1603722705 1736336059 1573409266 1139837145 1750061796 555938830 960244872 1281007247
result:
wrong answer 1st numbers differ - expected: '1692900670227', found: '683555603'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 18552kb
input:
1994 405 1995 556641 923161 368121 885153 370001 753533 356267 140326 312301 783041 203028 233351 298226 63313 481496 767119 609731 83601 244285 123019 322557 89764 320795 510500 597803 130811 616297 926775 53285 223840 767926 528855 663829 93371 7616 504897 555458 588585 439361 321306 318738 292666...
output:
-39002343766 -42401452486 -11075061179 -29285195405 -31913642575 11986872294 13483715757 -9469762288 14088038342 -30627225925 -15354749746 -46579449651 -8240192094 -52058356228 19683538367 -18093067124 -21525608276 15383412911 -18363413768 -19055107222 16682032057 -37402674229 -10156028986 -34502894...
result:
wrong answer 1st numbers differ - expected: '238065394611882', found: '-39002343766'
Test #3:
score: 0
Wrong Answer
time: 19ms
memory: 17404kb
input:
9999 7777 8888 350689 340640 742515 847983 603105 291777 123546 793423 123828 81197 689725 179719 163877 82548 81941 315278 837007 706985 328661 54846 70061 844381 44818 920226 401209 383073 958769 885881 704561 623241 296481 865665 638927 35204 446821 733545 906869 461290 504161 780939 437893 78051...
output:
25689733616 45422772328 -155281599236 -93292413703 -144118538321 -50678719490 38694467937 -105456289356 30521292290 -81022405125 -72557479231 43778782482 -5307163664 -129461969880 2972129306 -108676910301 -31828911079 -49463605574 -50649930752 19864667978 -67346177877 -48508348172 -5511715779 -36243...
result:
wrong answer 1st numbers differ - expected: '917941805267440', found: '25689733616'
Test #4:
score: 0
Wrong Answer
time: 625ms
memory: 26196kb
input:
80000 100 79999 636177 829001 946691 381143 658421 84345 812823 285627 753201 780625 199608 200621 758328 43837 174785 860657 837685 121124 628536 250361 57056 763835 854851 569459 704553 381031 452536 11521 83241 118985 952062 804495 957289 395051 600601 199598 983966 501357 608555 75049 620761 808...
output:
156827380282 -552346672672 -488442557796 -1195287277340 -625134494955 -510927077505 96392165436 674158668349 -277162773752 258132206822 897157038979 -397680021785 424193434189 -739275206738 -480830864175 1332318245448 531104087176 -566831464162 1234433267277 514477504509 -642535537928 584642009983 -...
result:
wrong answer 1st numbers differ - expected: '2049642206587450', found: '156827380282'
Test #5:
score: 0
Wrong Answer
time: 775ms
memory: 28736kb
input:
90000 100 89999 910319 741245 15001 621563 607827 958814 713422 778999 4129 398965 560121 469526 583062 793795 750877 765421 654537 761001 585305 45111 299016 489428 871086 858817 286721 387466 267822 198069 844341 963241 515351 85267 657201 1676 719041 823049 685279 461279 316045 966515 837671 6194...
output:
-46076937112 1028744531604 -408702458410 278931017171 1180111899769 594409319016 -192286013050 204163628697 2004981948407 1849993235636 56249436196 96982655414 477298003144 -159348107685 730909471293 -804350552335 46394103477 2006742287448 2073892639346 497105836361 -198412270393 47041494296 -169663...
result:
wrong answer 1st numbers differ - expected: '1387554777185384', found: '-46076937112'
Test #6:
score: 0
Wrong Answer
time: 547ms
memory: 25572kb
input:
77654 77600 78888 533241 917289 57915 11289 2116 27801 173446 367131 419217 781673 361526 442749 297129 775770 364138 523309 514521 483929 126657 426121 771921 846145 557801 368163 244436 901113 851505 582225 570386 407457 32071 958501 286399 163034 982921 45093 169525 152381 529601 317785 363958 43...
output:
-78853167868 -119569497324 -44603820575 -25752274558 -86124755849 17435287620 -90875713559 -17717341215 -141012001278 -95976637366 49550509333 -20016813475 -103392981334 -20062872224 -101352481346 53445094446 -18770547020 -169260839393 -46989015737 -17536162091 19355382797 -62930247288 -94274214271 ...
result:
wrong answer 1st numbers differ - expected: '6113515034912004', found: '-78853167868'
Test #7:
score: 0
Wrong Answer
time: 616ms
memory: 25304kb
input:
87654 87654 88888 11969 827905 718296 546441 34643 409376 899435 13745 273000 219440 121415 258869 607041 915541 54841 170243 312971 52666 551629 136173 199369 595404 804731 152679 911401 592177 652725 693627 612183 122796 697911 745150 951821 79862 490878 861269 683115 752401 96321 711061 79146 682...
output:
-40628667027 -29284271511 -2049221265 -109361247687 -137843672131 -66079155342 -221085594538 22921012633 20664164173 -19738129051 -124570804421 -46045103976 -192057815976 -237260491600 -22732301572 -213600263618 -254835196544 -143129960637 12765081724 -4944410417 6532059381 72099909541 -153204899394...
result:
wrong answer 1st numbers differ - expected: '190363861499245', found: '-40628667027'
Test #8:
score: 0
Wrong Answer
time: 1156ms
memory: 25456kb
input:
75757 80000 79797 484017 923271 503479 371693 407131 675651 128065 559955 230433 640753 664171 725701 411881 203961 604521 391313 135601 753991 596483 186409 795188 808589 915505 468366 796905 385309 144431 27036 750997 276351 306785 246681 417281 890361 604385 728641 183905 396657 608665 297185 965...
output:
264678294633 598730918 -68833565096 449019014279 296790720089 259602253335 98992615583 275363319320 -23306977435 458319242028 -186100885400 -136101021186 410914098302 272010193466 281606699827 250811200439 -7794902651 235777171611 -189344768993 408060732656 101377234722 134639387068 -147692960072 97...
result:
wrong answer 1st numbers differ - expected: '25165903994700905', found: '264678294633'
Test #9:
score: 0
Wrong Answer
time: 1246ms
memory: 28008kb
input:
85757 80000 89797 365071 866171 292001 203861 238608 342899 587741 829194 525736 476155 202388 341423 792260 152351 302911 498503 901389 69215 401983 799291 430211 108169 60713 908033 328701 585128 628465 666585 238471 886049 462521 9774 928664 402969 934216 458465 105337 302193 419801 55383 20031 7...
output:
-35675829768 -23487601891 79118551923 -63895546385 -4276497173 -89553615839 149764827431 -105710922245 -5034353758 -140567986727 -162860995570 -70609195467 -36376688741 -2756903564 -36457936813 -77361626517 82373966948 -34197026530 -98549020174 -324929226222 -42677916123 -90605306009 -157723086324 -...
result:
wrong answer 1st numbers differ - expected: '13723110684363256', found: '-35675829768'
Test #10:
score: 0
Wrong Answer
time: 1360ms
memory: 26040kb
input:
100000 100000 100000 830821 840887 527523 351839 415371 428013 117556 863473 387567 587411 883157 808805 956353 745921 952210 610807 502909 398921 659296 997417 610551 598717 567276 427661 755457 546291 617737 698135 997273 438737 935176 220641 697316 562857 850451 306042 323721 900500 653557 949002...
output:
-204331594381 -19057591692 -5395047738 334766534385 542947995005 46014342976 -113732134937 412314336293 310620367181 165035772206 -47012641388 250186392913 380446064864 28271437260 -53484387036 468753428490 324839938042 653118013165 192242333388 480521520802 84907004193 -151241784212 -209432899283 4...
result:
wrong answer 1st numbers differ - expected: '3080167687933299', found: '-204331594381'