QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793087 | #5297. 糖果公园 | gzy | 100 ✓ | 1465ms | 28576kb | C++14 | 2.6kb | 2024-11-29 16:36:37 | 2024-11-29 16:36:40 |
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 -= (ll) w[cnt[c[x]]--] * v[c[x]];
else res += (ll) 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;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 12388kb
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:
1692900670227 1924186465420 1788619871315 1428797039393 1638803139039 1480756606242 1901066789423 2041845801659 1985848300018 1667587147993 1513578549988 520246981646 2268702977160 1989850865295
result:
ok 14 numbers
Test #2:
score: 10
Accepted
time: 3ms
memory: 16568kb
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:
238065394611882 223351732514362 143518142036549 42044214436211 109743155475889 177630359398374 108826480159917 68443719001360 98175565588422 151122156822203 38630760979662 134660774822093 106107516790178 213081398740476 102798250931647 139753027646604 42219477747884 70976833077423 52195554003704 227...
result:
ok 1313 numbers
Test #3:
score: 10
Accepted
time: 22ms
memory: 15416kb
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:
917941805267440 1006016957808744 1861734516053244 579216191438073 1862931090087855 1344995639434238 1251244272171361 1104727635966388 975254385456642 890403137009147 1382606264122049 1299589213402386 729550722636784 779574605978664 1514159332595738 1016746305254179 289242808409113 625005716915898 14...
result:
ok 5882 numbers
Test #4:
score: 10
Accepted
time: 708ms
memory: 25860kb
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:
2049642206587450 10472519246193120 12790100258589340 15834477982093540 9806159591807765 12903774148329343 3290646931290172 25151379873786429 10876242183041800 23595661700162790 25845837090915203 10481225192730343 22306457104294477 14975077246537646 12939233429767377 32425732652864072 352779708392562...
result:
ok 79999 numbers
Test #5:
score: 10
Accepted
time: 818ms
memory: 28576kb
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:
1387554777185384 31621381136567956 13893402478208470 4488030129065427 32629754601835641 30324949009721960 10260471699229062 10875993365003929 37191985064091639 35554008721558708 9509539044542500 2336606436319670 4645437183986888 2502896052393563 28571570622001725 17040165591095025 23069565576402613 ...
result:
ok 89999 numbers
Test #6:
score: 10
Accepted
time: 591ms
memory: 25728kb
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:
6113515034912004 3376386150122260 4462267502933473 3766793710303618 3226666970154103 4193589143363652 14086560041576425 9191427044463585 14263015881285122 8947961578437706 9753426358486293 7053020657855069 15472855593275050 8262822704766304 1653130343996862 8023778203495470 643586373725876 124099325...
result:
ok 78888 numbers
Test #7:
score: 10
Accepted
time: 665ms
memory: 25240kb
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:
190363861499245 2534748744677993 2532594136341871 15065862819007033 10976501484780477 3350025591593842 13094674638408790 245235488843161 99608070856525 9285317303733605 4095603487301435 11941698204563608 15381967024835672 14924400430953648 14892660402461436 17042049126539838 12129389938703744 968207...
result:
ok 88888 numbers
Test #8:
score: 10
Accepted
time: 1033ms
memory: 26724kb
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:
25165903994700905 15524928689268902 4704213140711000 13020934434614407 32689855521291865 30018215530726935 2615927349407903 16915604626656792 2546918069354341 17665340980110124 16376751832029288 12670532818254334 11241899400858750 25185062585772602 25996597662923571 7541723756704695 1361213370087813...
result:
ok 66533 numbers
Test #9:
score: 10
Accepted
time: 1465ms
memory: 26996kb
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:
13723110684363256 2799307346912029 4904974720256883 25929980815300079 2643251741447403 33563855798944801 5807323506141479 26107407048594939 7334643761011618 17213328145169881 27504163457494030 10498779377380917 1126099753355163 6663166556437876 15448226466367571 8917756508586603 5134221855095908 151...
result:
ok 74681 numbers
Test #10:
score: 10
Accepted
time: 1325ms
memory: 27024kb
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:
3080167687933299 1059338920934004 9423921651522246 16037502131629809 8474947214699901 1468469563041600 2505905195800551 10217473791589413 16159888848365901 5267452798044462 6370622142940564 17543538028143953 7109998724923616 1434053427062220 1343017148810532 14011266253303818 12940240964032506 20605...
result:
ok 83167 numbers
Extra Test:
score: 0
Extra Test Passed