QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307729 | #7839. 虹 | zyc070419 | 100 ✓ | 1595ms | 806172kb | C++14 | 6.4kb | 2024-01-19 07:54:13 | 2024-01-19 07:54:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 8e4 + 3;
const int mod = 20242024;
const int A = 19901990;
const int M = 285;
const int B = 282;
inline int read() {
char ch = getchar(); int x = 0;
while (!isdigit(ch)) {ch = getchar();}
while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
return x;
}
struct node {
int id, l, r;
}q[N];
int n, prime[10000], p[N], pw[N], cnt, fa[N], top[N], son[N], sz[N], T, depth[N], pre[N], suf[N], lca[M][M], Ans[N], pos[N];
int v[N][3];
short Gcd[M][M];
bitset<N> vis, a, mem[N];
vector<int> g[N];
inline int calc(int x, int y) {
int ans = 1, res;
for (int i = 0; i < 3; ++i) {
if (v[x][i] <= B) res = Gcd[v[x][i]][y % v[x][i]];
else if (y % v[x][i]) res = 1;
else res = v[x][i];
ans *= res; y /= res;
}
return ans;
}
void init() {
n = read(); T = read();
for (int i = 1; i <= n; ++i) a[i] = (read() & 1);
v[1][0] = v[1][1] = v[1][2] = 1;
for (int i = 2; i <= n; ++i) {
if (!vis[i]) {
prime[++cnt] = i; pos[i] = cnt;
p[i] = i; pw[i] = i;
v[i][0] = i;
v[i][1] = v[i][2] = 1;
}
for (int j = 1, k; j <= cnt && i * prime[j] <= n; ++j) {
k = i * prime[j];
vis[k] = 1;
p[k] = p[i];
v[k][0] = v[i][0];
v[k][1] = v[i][1];
v[k][2] = v[i][2];
if (v[k][0] == 1 || v[k][0] * prime[j] <= B) v[k][0] *= prime[j];
else if (v[k][1] == 1 || v[k][1] * prime[j] <= B) v[k][1] *= prime[j];
else v[k][2] *= prime[j];
if (p[i] == prime[j]) pw[k] = pw[i] * prime[j];
else pw[k] = pw[i];
if (i % prime[j] == 0) break;
}
}
for (int i = 0; i <= B; ++i) {
Gcd[i][0] = Gcd[0][i] = i;
for (int j = 1; j <= i; ++j)
Gcd[i][j] = Gcd[j][i] = Gcd[i % j][j];
}
}
void dfs1(int x, int pa, int d) {
fa[x] = pa; depth[x] = d; sz[x] = 1;
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;
if (son[x]) dfs2(son[x], anc);
for (auto y : g[x]) {
if (y == fa[x] || y == son[x]) continue;
dfs2(y, y);
}
}
inline int LCA(int x, int y) {
while (top[x] != top[y]) {
if (depth[top[x]] < depth[top[y]]) swap(x, y);
x = fa[top[x]];
}
if (depth[x] > depth[y]) swap(x, y);
return x;
}
inline int get(int l, int r) {
int posl = (l - 1) / B;
int posr = (r - 1) / B;
if (posl == posr) {
int x = l;
for (int i = l + 1; i <= r; ++i) x = LCA(x, i);
return x;
}else {
int x = LCA(suf[l], pre[r]);
if (posl + 1 < posr) x = LCA(x, lca[posl + 1][posr - 1]);
return x;
}
}
vector<int> vec, ex[N], val[N];
bitset<N> in, now, fin;
void dfs(int x) {
now[x] = 1;
for (auto id : ex[x]) mem[id] ^= now;
for (auto y : g[x]) {
if (y == fa[x]) continue;
dfs(y);
}
now[x] = 0;
}
void work(int i) {
fin = (now & mem[i]);
fin >>= (q[i].l);
fin <<= (q[i].l + N - q[i].r - 1);
Ans[i] = 1ll * fin.count() * A % mod;
Ans[i] = (Ans[i] + q[i].r - q[i].l + 1) % mod;
}
void dfs3(int x) {
for (int i = pw[x]; i <= n; i += pw[x]) now[i] = a[calc(x, i)];
for (auto i : val[x]) work(i);
for (int i = pos[p[x]]; i <= cnt; ++i) {
if (1ll * prime[i] * x > n) break;
dfs3(prime[i] * x);
}
for (int i = pw[x]; i <= n; i += pw[x]) now[i] = a[calc(x / p[x], i)];
}
int main() {
init();
for (int i = 1, x, y; i < n; ++i) {
x = read(); y = read();
g[x].push_back(y); g[y].push_back(x);
}
dfs1(1, 1, 1); dfs2(1, 1);
for (int i = 1; i <= n; ++i) {
if (i % B == 1) pre[i] = i;
else pre[i] = LCA(pre[i - 1], i);
}
for (int i = n; i >= 1; --i) {
if (i == n || i % B == 0) suf[i] = i;
else suf[i] = LCA(suf[i + 1], i);
}
for (int i = 1, o = 0; i <= n; i += B, ++o) lca[o][o] = suf[i];
int mx = (n - 1) / B;
for (int i = 0; i <= mx; ++i)
for (int j = i + 1; j <= mx; ++j)
lca[i][j] = LCA(lca[i][j - 1], lca[j][j]);
for (int i = 1, opt; i <= T; ++i) {
opt = read();
if (opt == 1) {
q[i].id = 0;
q[i].l = read();
q[i].r = read();
int x = get(q[i].l, q[i].r);
if (x != 1) ex[fa[x]].push_back(i);
}else {
q[i].l = read();
q[i].r = read();
q[i].id = read();
}
}
for (int i = 1; i <= n; i += B) {
for (int j = 1; j <= T; ++j) {
if (q[j].id != 0) continue;
if (in[j]) continue;
if (q[j].r < i || q[j].l > i) continue;
vec.push_back(j);
in[j] = true;
}
if (vec.empty()) continue;
sort(vec.begin(), vec.end(), [&](int x, int y) {return q[x].l > q[y].l;});
int o = 0;
for (int j = i, x; j >= 1; --j) {
x = j;
while (!now[x]) now[x] = true, x = fa[x];
while (o < vec.size() && q[vec[o]].l == j) mem[vec[o]] |= now, o++;
}
now.reset(); o = 0;
sort(vec.begin(), vec.end(), [&](int x, int y) {return q[x].r < q[y].r;});
for (int j = i, x; j <= n; ++j) {
x = j;
while (!now[x]) now[x] = true, x = fa[x];
while (o < vec.size() && q[vec[o]].r == j) mem[vec[o]] |= now, o++;
}
now.reset(); vec.clear();
}
for (int i = 1; i <= T; ++i) {
if (q[i].id != 0) continue;
if (in[i]) continue;
for (int j = q[i].l, x; j <= q[i].r; ++j) {
x = j;
while (!now[x]) now[x] = true, x = fa[x];
}
mem[i] = now; now.reset();
}
dfs(1);
for (int i = 1; i <= T; ++i) {
mem[i] ^= mem[i - 1];
if (q[i].id != 0) val[q[i].id].push_back(i);
}
now.reset();
for (int i = 1; i <= n; ++i) now[i] = a[1];
for (auto i : val[1]) work(i);
for (int i = 1; i <= cnt; ++i) dfs3(prime[i]);
for (int i = 1; i <= T; ++i)
if (q[i].id != 0) printf("%d\n", Ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 23664kb
input:
998 1000 955556485 952505211 899166521 258704448 894183248 636280051 62949347 983956660 113872828 588367167 208142006 665025449 944228063 284736189 169202015 56096447 404419923 30158095 111191865 717455344 790159420 391379127 208279658 426780799 886604643 940903663 618716147 773652834 385881251 1593...
output:
16521790 13341944 16841705 2220375 880451 3621051 12662029 6300750 3240463 2400556 6501168 3580517 9221391 8381420 12982211 8001004 9361122 17262479 3600913 10401408 16202143 15022309 16341874 7861442 1560390 8340899 12421304 13961591 10421679 12101636 17361912 11781615 4780673 13641787 20102392 171...
result:
ok 490 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 23484kb
input:
1000 997 103470799 773962597 977631665 55926526 616833039 263471628 825848455 638144717 340710593 68036397 623497249 808915869 345157828 256095693 400262335 173843004 238983751 646376872 243739767 221162275 465477137 772061029 840064611 274062983 522264159 689460088 20129595 287189331 622217799 6948...
output:
13621441 17282360 11241382 15841876 17222347 1880319 12441746 10381083 18222171 7341024 10081427 2900456 2900406 13801602 17521768 19901997 8521022 13281468 2400503 17201967 19942477 14461494 19742168 14461471 12121799 2600806 18902095 1941004 19901993 10221200 8901579 9201080 19442423 720422 130019...
result:
ok 527 lines
Test #3:
score: 0
Accepted
time: 7ms
memory: 23460kb
input:
1000 1000 1697351 841785432 606301324 899151762 398181773 419939453 419455373 826820357 965555426 240847697 718049384 378823565 364137136 867089279 445499605 934770217 134914678 642584637 766848023 203338778 153291975 240768524 446186401 462123008 408740063 755064293 274502953 646610365 27815415 164...
output:
368 198 7021295 16001721 18602311 8021119 17201976 1380573 13141934 3580444 14641604 16681966 3240524 16182225 7541265 8520964 6341385 18922654 17861873 13781440 11581327 14342249 3600640 6821000 16841702 860350 16501686 3420674 18881910 6161028 17022054 3920543 4600572 6300810 3761005 11401360 8181...
result:
ok 502 lines
Subtask #2:
score: 20
Accepted
Test #4:
score: 20
Accepted
time: 1053ms
memory: 659112kb
input:
65531 65535 968854923 932574892 192297572 866236747 654755663 148562561 273214896 947434573 938626677 992982166 219888853 229840279 676071061 383387319 372883953 729287797 601010887 31942080 990584163 823724544 181337075 918252129 896876911 768539961 357780649 890577681 819641335 320266037 55445939 ...
output:
2662122 12263904 9988949 9098885 10661570 169420 12206075 11189204 12737561 19687277 3177635 12864425 16522132 8890301 19817862 19631288 14433359 4841805 15087340 13737927
result:
ok 20 lines
Test #5:
score: 0
Accepted
time: 1025ms
memory: 659408kb
input:
65534 65536 820462503 674023407 678774031 936839760 967886021 931679487 453790312 457688550 70497701 344893727 154301715 507005683 73026386 390834155 323019588 839428562 139619227 778200763 402648418 434214668 203135761 709945633 736891475 834231887 757898689 714927300 773615727 495008913 178272181 ...
output:
3556992 16638524 17773272 4500556 15023833 15616791 16530231 2941967 3166188 12186952 18098140 476862 4445062 9237154 8863687 143980 14070479 6047549 7425512
result:
ok 19 lines
Test #6:
score: 0
Accepted
time: 1104ms
memory: 658952kb
input:
65536 65536 405634173 17394581 118925347 922474073 743773645 237837181 499268357 244246848 939786401 792695975 628358275 678027475 348815741 419958879 726832416 24340945 901834373 56505761 405488783 771756785 890119785 252669240 492790889 529308875 31501425 546890993 105451499 269507525 583855527 42...
output:
14813680 12244780 5372831 129044 15936400 19557428 17514428 4965101 11035792 17705809 19062063 9585446 1382379 17154907 17605748 17161957 6292833 16315460 11100885 4587223
result:
ok 20 lines
Subtask #3:
score: 20
Accepted
Dependency #2:
100%
Accepted
Test #7:
score: 20
Accepted
time: 1179ms
memory: 660036kb
input:
65536 65533 30932122 78382923 537901462 43608430 743690928 918369886 474585919 91526068 574096807 937639556 275209310 841686338 356806157 792932071 603518094 832348491 468678335 713509816 101484129 852321989 436384847 445099357 227895189 501297162 399636691 271485365 207312863 509602081 865283531 19...
output:
1496564 9125549 16577986 6310026 1063976 16707 52957 14908581 14790251 14722135 13755277 11137460 5968935 8549164 18541922 24957 1930126 16330833 14364850 2239625 10619499 16538 6589616 2426893 19692596 19164930 15643210 18580925 12236638 6881655 2537792 9181 5316249 16956425 5578816 5938013 7323269...
result:
ok 45533 lines
Test #8:
score: 0
Accepted
time: 1117ms
memory: 659976kb
input:
65536 65535 896327463 680912869 425088586 463001926 222746654 139797223 797862825 191243957 970951057 833986727 442405892 825555128 314556958 914737211 212060430 912767901 453296903 873665049 564716803 471005323 213780115 573452539 543739081 881018559 902197811 297810647 51022403 757374500 594296052...
output:
3765898 7160189 1840871 8384498 12162436 17733710 213192 867756 9465798 5355255 9688576 14003307 3802366 3494697 2813852 18250238 14202178 3534428 4309535 12426295 20119652 19552024 19554541 276659 9217790 4968412 4966695 8795674 14327484 5321111 5143428 4804826 14976742 1065939 6768277 11126616 392...
result:
ok 25535 lines
Test #9:
score: 0
Accepted
time: 1182ms
memory: 660836kb
input:
65536 65536 273612167 315772190 71207511 736212317 523695534 424195293 720590001 84825693 594307129 913990193 946510345 222887460 962253802 124933747 293256949 752514778 915822505 86321273 339054171 563974341 489916343 956984316 111089551 70521376 292460752 45000461 214783067 288398507 49055118 1032...
output:
8409099 627948 11730380 8939261 10928253 17059110 6990391 13342784 4902327 5950655 16232329 8204509 19093841 4451012 18709415 3229726 10846229 5082475 17190005 14833410 5282247 2331065 10279617 4557434 7700054 8071957 10999644 1165013 95904 113129 12805875 15919700 10967571 3128343 12049502 18201862...
result:
ok 55536 lines
Subtask #4:
score: 30
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #10:
score: 30
Accepted
time: 1194ms
memory: 659508kb
input:
65536 65536 690710135 657115917 211163039 197295969 367013816 156855111 797052165 886430858 508869157 17134147 61796741 347521885 250213399 668920827 220381843 208336869 792057463 245539955 861408575 952059033 360332858 249610287 456737865 567698963 120715589 263131517 574343202 122801665 999840299 ...
output:
8040100 3021434 9107120 13724129 19834787 14940549 6403684 523398 5240085 12839771 3633093 11132658 20077338 11562974 4875599 14609248 9659750 16422583 8666268 18202469 9564561 15213093 11526145 19105135 5273205 14674017 13442536 3940980 11196942 12398974 4242874 17444381 10527254 7117230 7801758 84...
result:
ok 32817 lines
Test #11:
score: 0
Accepted
time: 1159ms
memory: 660144kb
input:
65536 65536 170304261 71878445 697047463 26536118 288496955 296519416 798352076 455901935 112317553 316596485 118780647 983962473 147855782 547028521 787615861 195975475 707627127 396956425 88941067 567087327 710386346 98438291 66729629 279815862 826118743 223108495 928573999 931742906 643699659 746...
output:
26156 23416 44529 18790437 179412 5345034 19864608 17193359 1683682 1101789 17202182 3942854 19699539 17312852 17869402 10804850 19613278 1205247 17596278 1441167 12820276 9278420 6946809 4827331 17854429 16854274 7013401 15197353 7634324 6573386 10812965 15740317 12416100 14805172 8791862 3555911 9...
result:
ok 54616 lines
Test #12:
score: 0
Accepted
time: 1102ms
memory: 659440kb
input:
65534 65536 418820062 329896341 692391895 395362428 157193467 129138716 640964346 56172381 600587925 363136405 238370903 160128513 51235613 595121292 416717709 911948685 369399841 324706983 564913713 142006521 995220829 569218724 960953803 110442236 988689878 329122927 579650897 494130281 805483377 ...
output:
3722534 1642037 9000155 26797 18260516 10141151 5996188 11901875 647641 10326901 3849463 602819 7461708 4343389 17664484 14508412 9241911 3121606 19839193 11299183 8386787 16550463 12550737 19282100 4112538 1119285 6373193 4966374 15020078 14303001 5617046 12265071 5530990 10673373 6236623 19571786 ...
result:
ok 11161 lines
Test #13:
score: 0
Accepted
time: 1195ms
memory: 660164kb
input:
65535 65536 40159670 616546517 635130937 77466737 659136612 932097848 379284085 520067901 644270537 520589915 334168227 587475447 428153433 654877316 858838608 415007221 904452303 468994015 92514149 443749003 804933427 233837837 917210605 742865247 172477723 256829127 955032199 218062404 156945304 3...
output:
4012 5004225 18430554 3269256 8444471 16539477 8812413 2939774 20334 18636194 998 11368250 9047594 3334145 14142232 19923541 17860027 4322674 3460905 6286005 16367286 3866104 19582855 16842599 2606835 13525740 9097458 11249615 20312 12361947 8362814 14378671 1687058 9988709 6046604 1003937 16605 137...
result:
ok 32813 lines
Test #14:
score: 0
Accepted
time: 1140ms
memory: 666508kb
input:
65535 65536 282726917 194315094 983494371 997843378 434298909 899659941 494211327 973321579 742895953 226060139 337435275 554934675 7189175 241187709 796709538 92708973 342166395 453751106 373939199 40714295 78999882 8885357 287039037 979321771 124201556 310605183 317016708 996799011 921717869 53692...
output:
16953 13209 177 10825744 30571 17726724 11265362 18429393 4375308 17352613 5480947 12386497 14554025 5733475 5562660 14236964 10039934 15761002 13542015 19256578 806936 1584266 8229552 3958243 15412478 8546981 2182278 9691184 18870420 7753928 7324840 8673769 5524414 13100958 19424461 4554734 1654576...
result:
ok 32656 lines
Subtask #5:
score: 20
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #15:
score: 20
Accepted
time: 1574ms
memory: 802752kb
input:
79999 79996 635394353 806780511 826597371 793762079 333138314 429096159 401894869 625722149 616526293 367571207 711713149 597366281 666979179 244748289 564660251 985817954 246396913 425479439 995583415 850880133 47931612 775966469 941900917 207077751 257486961 877578787 53990419 484584707 923646540 ...
output:
29937 1910 16830515 141512 14313981 6068327 13233150 12747739 11125779 4187083 8092951 9155432 10499223 6136617 13028827 2622655 1231814 11082105 14675789 6442229 18388790 17709422 8825438 14739801 7287870 19857977 9539588 10827879 11224843 8961140 18382324 19466400 8331588 16823579 383399 3900868 1...
result:
ok 40096 lines
Test #16:
score: 0
Accepted
time: 1522ms
memory: 801188kb
input:
79998 79999 608035833 149278714 290869512 991618649 451971119 974701573 181943435 344458834 627923214 382919143 508808203 111862226 35754921 885058650 530953550 45952737 629847463 640317358 318872628 860836707 292340265 133012941 238508349 347870703 177823619 577767736 914920793 930293605 283499148 ...
output:
5885923 17576214 2167564 15582449 7788481 2219448 14858236 15755520 5382526 5314607 4052334 16001822 3626340 18021589 11845386 5847998 17062126 19659913 19424762 5121351 15267491 1813420 5949567 3162466 6084055 5205866 11401181 10897958 19750634 5028699 1692067 16047192 2724868 10727973 7369422 6665...
result:
ok 8904 lines
Test #17:
score: 0
Accepted
time: 1595ms
memory: 802568kb
input:
80000 80000 620891279 314795903 843880649 65086746 120446681 548948399 480807963 6685633 229258305 99985531 976659026 187591336 487780589 68869183 520113483 579568547 17909785 920271485 932516785 926606319 932035361 917385743 593992325 162667837 684536933 664104427 351611569 122422039 377593479 8633...
output:
44198 3544 4890 4117 41678 9578 14461 32587 667 20753 5151 14359 71169 15142 23637 40570 71527 7776 11479 69956 14686442 9684357 4444878 12702546 14693596 12545794 7386314 3322278 19566490 15754163 14677478 6847938 16493120 8610996 592245 408155 4141943 4921488 3024224 6645554 9091672 16435684 18037...
result:
ok 68613 lines
Test #18:
score: 0
Accepted
time: 1370ms
memory: 803044kb
input:
79999 80000 91783769 450826957 248644981 2675243 967851313 723278977 195366587 961567794 714461297 708977345 347748673 89614657 638796360 642806175 427800287 614118479 482476163 225735577 808069831 771141445 256198415 799182884 852605327 178454179 614787258 470097513 589706543 602634407 440272857 25...
output:
78977 79661 79261 78950 79534 78914 79080 79061 79041 79416 78730 79222 79162 78675 78666 79254 79281 78321 79747 79655 79192 79136 78751 79126 78812 79143 78750 79381 79572 79552 79165 78515 79632 79660 79065 78459 79926 79767 79693 79663 78688 78896 79342 79258 78987 78965 79920 78802 79071 78498 ...
result:
ok 80000 lines
Test #19:
score: 0
Accepted
time: 1389ms
memory: 801364kb
input:
79999 80000 682743924 614832237 899869835 540431151 822786317 227945133 935983411 989231359 721490075 628101733 524189189 689132165 928325490 212442524 320218045 312739603 206920221 507339380 546897299 483226477 530685639 824134755 83443741 822814147 968776935 244416033 132524577 752446425 299256219...
output:
79206 78399 79154 79089 79794 79582 79229 78896 78901 79529 79383 79177 79344 79153 79188 78771 78840 79185 78476 79474 79230 78750 79415 79026 78980 79529 79195 78798 79102 79614 78992 78735 78861 79606 79399 78942 79020 78759 79400 78898 78685 79187 79119 79165 78815 79220 79301 79023 78934 78956 ...
result:
ok 80000 lines
Test #20:
score: 0
Accepted
time: 1547ms
memory: 806172kb
input:
80000 79996 513551673 392710681 809819869 294630781 357976969 977317841 893482480 140598408 919495755 859788887 757358168 456763555 467040695 163540455 850001989 869235571 730673055 972214053 658305363 757224641 960452273 808330129 79574079 410677408 489598301 441993771 1025449 503166145 873150027 3...
output:
79176 79032 79691 78645 79222 78677 79857 79289 19300869 19960816 1299594 5039597 7099916 17780451 16721279 17541238 1779153 15560727 19060427 16600530 4260014 18320831 79887 12340290 14240397 7700022 17361312 13860396 16940809 13341121 7740334 6719659 6720068 5699452 6380184 6719750 13700357 672023...
result:
ok 72752 lines