QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#312610 | #8133. When Anton Saw This Task He Reacted With 😩 | ucup-team484 | AC ✓ | 906ms | 43108kb | C++17 | 3.2kb | 2024-01-24 05:36:15 | 2024-01-24 05:36:16 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef array<int, 3> vec;
typedef array<vec, 3> mat;
const int mod = 998244353;
const int N = 1e6 + 5;
mat left(vec p) {
return mat{vec{0, -p[2], p[1]}, vec{p[2], 0, -p[0]}, vec{-p[1], p[0], 0}};
}
mat right(vec p) {
return mat{vec{0, p[2], -p[1]}, vec{-p[2], 0, p[0]}, vec{p[1], -p[0], 0}};
}
mat leaf(vec p) {
return mat{vec{p[0], 0, 0}, vec{p[1], 0, 0}, vec{p[2], 0, 0}};
}
vec operator*(mat p, vec q) {
vec r = {0, 0, 0};
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
r[i] = (r[i] + p[i][j] * 1ll * q[j]) % mod;
return r;
}
mat operator*(mat p, mat q) {
mat r;
for (int i = 0; i < 3; i++) {
r[i] = {0, 0, 0};
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
r[i][j] = (r[i][j] + p[i][k] * 1ll * q[k][j]) % mod;
}
return r;
}
struct segment_tree {
using data = mat;
data id = mat{vec{1,0,0}, vec{0,1,0}, vec{0,0,1}};
static data combine(data dl, data dr) {
return dl * dr;
};
int n, h;
vector<data> t;
segment_tree(int n = 0) : n(n), h(32 - __builtin_clz(n)), t(2 * n) {}
segment_tree(vector<data> & a) : segment_tree(a.size()) {
for (int i = 0; i < n; i++)
t[i + n] = a[i];
for (int x = n - 1; x > 0; x--)
t[x] = combine(t[x << 1], t[x << 1 | 1]);
}
void build(int x) {
while (x >>= 1)
t[x] = combine(t[x << 1], t[x << 1 | 1]);
}
// set the data at the position i
void setValue(int i, data d) {
i += n;
t[i] = d;
build(i);
}
// query the data on the range [l, r[
data query(int l, int r) {
l += n; r += n;
data dl = id, dr = id;
for (; l < r; l >>= 1, r >>= 1) {
if (l & 1)
dl = combine(dl, t[l++]);
if (r & 1)
dr = combine(t[--r], dr);
}
return combine(dl, dr);
}
};
int L[N], R[N], s[N], par[N], idx[N], head[N], en[N], curt = 0;
vec a[N];
segment_tree seg;
int dfs(int u, int p = -1) {
if (!u) return 0;
par[u] = p;
int x = L[u], y = R[u];
s[u] = 1 + dfs(x, u) + dfs(y, u);
if (s[x] <= s[y])
swap(x, y);
if (R[u] != 0)
a[u] = left(a[L[u]]) * a[R[u]];
return s[u];
}
void upd(int u) {
int x = L[u], y = R[u];
seg.setValue(idx[u], !x ? leaf(a[u]) : (s[x] > s[y] ? right(a[y]) : left(a[x])));
}
void dfs2(int u) {
if (!u) return;
idx[u] = curt++;
int x = L[u], y = R[u];
if (s[x] <= s[y])
swap(x, y);
head[x] = head[u];
head[y] = y;
en[u] = u;
dfs2(x);
dfs2(y);
if (x != 0)
en[u] = en[x];
upd(u);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, q; cin >> n >> q;
for (int i = 1; i <= n; i++) {
char c; cin >> c;
if (c == 'x')
cin >> L[i] >> R[i];
else
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
dfs(1);
seg = segment_tree(n + 1);
head[1] = 1;
dfs2(1);
while (q--) {
int i; cin >> i;
cin >> a[i][0] >> a[i][1] >> a[i][2];
while (i > 0) {
upd(i);
int j = head[i];
auto p = seg.query(idx[j], idx[en[i]] + 1);
a[j] = vec{p[0][0], p[1][0], p[2][0]};
i = par[j];
}
cout << a[1][0] << " " << a[1][1] << " " << a[1][2] << "\n";
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 15908kb
input:
5 3 x 2 3 v 1 0 1 x 4 5 v 0 2 1 v 1 1 1 4 1 2 3 5 0 1 1 4 0 2 2
output:
-2 0 2 1 -2 -1 0 0 0
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 906ms
memory: 38276kb
input:
199999 100000 x 137025 65661 v 572518668 158967010 74946561 x 129836 192657 x 141948 187810 v 574918069 328924434 141474729 x 143312 111002 x 52772 148497 v 922857701 690080961 651915759 v 656198340 28002884 129579416 v 639893144 265359784 646791226 v 796871409 411409966 598676495 v 882562617 224394...
output:
393120558 -224477738 -610947005 -238284787 981774500 128012497 -703632542 980011608 533642029 404379574 -252947501 -944750793 -593678852 828869760 78021156 -405749495 647751304 881427733 190018467 -483001218 -480063798 628180500 -488259799 -740814218 -984507108 352087791 917410487 -66193044 36659122...
result:
ok 300000 numbers
Test #3:
score: 0
Accepted
time: 793ms
memory: 41452kb
input:
199999 100000 x 154525 80092 v 450407262 725458410 590777520 x 24720 135901 v 719242117 114943104 186796011 v 382530926 89156744 943939337 x 183376 26042 x 109984 157873 x 151637 150600 x 4115 27454 x 163135 92648 x 16764 33212 v 849210403 945083972 689295397 v 471196117 68587428 225597765 x 24643 5...
output:
-321176892 -1730057 -549077502 810403092 258196842 853459733 -587488197 -744895835 -85579882 327134890 519245783 922528759 317367558 536888537 506214109 -513490823 -119198571 -225839405 422920052 152084658 517340457 1207902 348787162 320821077 776293878 699474926 711114530 -126385880 -529746765 -176...
result:
ok 300000 numbers
Test #4:
score: 0
Accepted
time: 650ms
memory: 41464kb
input:
199999 100000 x 72889 193806 x 35339 33069 v 314802407 406980523 492377265 x 108307 60027 x 144922 140917 v 328481079 117663280 644171354 v 482028404 951751561 166221217 v 936461869 436114879 421819757 x 152919 99965 x 61168 150607 v 56403640 743462679 134896557 v 24809217 462947115 966139991 v 7828...
output:
-974534477 380448367 629159667 -237565933 539369190 611778104 114926687 -344551438 -58366939 -324044883 304745735 544123803 -44444241 186017361 49200537 -670961571 871001677 293980713 588783157 -496113704 -807680056 -895563447 993889016 963478755 -488231872 105416897 281770975 -187161547 367139818 4...
result:
ok 300000 numbers
Test #5:
score: 0
Accepted
time: 606ms
memory: 36592kb
input:
199999 100000 x 134204 79203 v 152855933 152545887 271660214 v 393332175 182708769 115884220 v 731792305 965028257 676889584 x 89631 14495 x 142016 85686 v 600051847 172947969 906920949 v 846126215 214556203 657929902 x 125721 133526 x 93179 35713 v 330716449 450417250 611411649 v 114397688 58644961...
output:
-858646737 375474977 14619793 -108915893 79727434 363703631 397351102 -120282751 -569198163 -409876008 819425899 502148739 -477665442 186408072 484373545 -355756 816534316 338411279 -664078084 288211584 608252640 509280845 -635271961 -711828658 -634847393 878881251 3658455 -286973481 94816531 100279...
result:
ok 300000 numbers
Test #6:
score: 0
Accepted
time: 558ms
memory: 41472kb
input:
199999 100000 x 29842 60343 x 22382 27649 v 148997533 411153785 529195552 v 831453378 856711025 439562917 x 183061 152107 v 208562249 845550020 248974502 x 8708 152913 v 901332053 480035531 424365358 v 120556946 620074725 884675784 v 493886564 455460926 851190410 x 63346 64739 x 35246 36255 v 762936...
output:
-761447031 190218414 70559261 -336478455 266356472 481630021 410967670 -384515050 -194236197 92638320 -960317575 -915320148 357869883 -765477642 -418635821 -306542271 124868602 187367212 -760633664 608489848 581104410 848616732 -90371214 -138436462 -383619738 454674844 673629667 485784731 -254318215...
result:
ok 300000 numbers
Test #7:
score: 0
Accepted
time: 554ms
memory: 34784kb
input:
199999 100000 x 179471 175117 x 189060 178495 x 20142 58065 x 22916 150184 v 704047412 186112247 660817663 v 761554808 199099716 794321264 v 362925435 508140595 251556541 v 65674025 717152823 157775106 v 325965317 977108704 50644678 v 566946741 833186394 771714200 v 996708965 76780827 625429369 v 85...
output:
365258325 105829774 -385846523 -266735298 -421343908 663777200 -444725676 -582790078 7683807 468131249 577225931 -484650068 215590236 861146274 -185423961 669985796 229486834 -433552590 -69012487 -478016304 774609748 -968294064 -428877962 721072115 644573107 513714638 -443786200 728007201 423847330 ...
result:
ok 300000 numbers
Test #8:
score: 0
Accepted
time: 553ms
memory: 39992kb
input:
199999 100000 x 73506 171332 x 135330 187765 v 308206068 679940956 278078069 v 442448744 196158033 738117032 x 194709 115786 v 208526122 936976225 340056181 x 42663 43401 x 55484 199464 v 865443128 131903961 74265613 x 44659 44773 x 32199 18455 v 986118756 284329619 244212114 v 793747964 649179736 4...
output:
-568527314 868308596 -823225834 -31998235 532451840 -225112347 457086098 -366456073 989689243 550574851 -991537585 416615899 285141084 -492917864 916518702 -540778964 653530244 -46638582 -384032521 767828057 -953970559 698196640 -503306580 99337798 718503234 -576166316 151379051 -977724006 707143833...
result:
ok 300000 numbers
Test #9:
score: 0
Accepted
time: 572ms
memory: 42512kb
input:
199999 100000 x 109220 170287 v 563361501 367416904 98790213 x 31431 96958 x 99594 159052 x 95382 129615 v 61965807 547448247 405891792 v 443530416 578856323 588763197 v 761021716 795533831 212530056 v 370964907 391812631 255457982 x 49713 153066 x 141543 111694 v 144135957 614962153 284136518 x 416...
output:
433293962 -661330106 747368803 -6126833 9180464 -838628109 -514418394 496735833 -33736634 912495370 -260958569 595438897 -531120857 44306423 -436174061 -94756115 42971643 -936828694 -728391208 336741491 -433105475 -71245255 134871683 -720629537 -353517322 476324825 -928623072 -13375740 112590560 -30...
result:
ok 300000 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 15856kb
input:
3 1 x 2 3 v 998244352 998244352 998244352 v 0 0 0 3 1 2 0
output:
-998244351 998244352 998244352
result:
ok 3 number(s): "2 998244352 998244352"
Test #11:
score: 0
Accepted
time: 561ms
memory: 43108kb
input:
199999 100000 x 199465 1690 x 70268 106693 v 194793703 729830314 457557419 x 64673 6910 v 755452906 141328541 558160677 v 725017524 158685295 201414156 x 161801 27226 x 181414 47025 v 387724146 819109666 514628998 v 252532326 97757436 828777580 v 200868967 692540096 706977766 v 300419109 2053530 824...
output:
-371033836 640945891 400484640 -692602867 893058825 99893167 -262515265 805595533 283037791 -621173639 357962902 336785549 835938680 -363549622 -975855419 -504547421 612552793 516945234 963890355 -480713478 -950021127 215318080 -255660608 -618453331 -863169608 970450812 921824280 -911671971 48169624...
result:
ok 300000 numbers
Test #12:
score: 0
Accepted
time: 529ms
memory: 41376kb
input:
199999 100000 x 37758 141919 v 148792593 369372129 595139892 x 59335 149367 v 452667329 904801829 628919068 v 160106559 532238331 179544300 v 850489754 705167899 265598880 x 120963 167491 x 92157 46815 v 444945978 987276260 843838004 x 189040 28027 v 889755401 760730228 3237333 x 168907 82672 v 2329...
output:
-101058855 -820807337 653646802 -949384144 -114729541 764698776 -493156041 -412281905 546090395 -83998326 -457300186 682989725 -32409202 -194537930 302298107 -545247818 -283460866 961852197 -115526544 -572284599 886391042 -794577049 -543580851 78105722 -486048218 -271026126 418204527 -723309552 -727...
result:
ok 300000 numbers
Extra Test:
score: 0
Extra Test Passed