QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309139 | #8133. When Anton Saw This Task He Reacted With 😩 | ucup_team_qiuly# | WA | 972ms | 28452kb | C++17 | 2.5kb | 2024-01-20 15:04:27 | 2024-01-20 15:04:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define mid ((l+r)/2)
const int N=2e5+5,MOD=998244353;
int n,m,dfsT,ord[N],ch[N][2];struct Point {int fa,dep,sz,hv,top,bot,dfn;}pt[N];
struct Matrix {int a[3][3];}sg[N*4];struct Vector {int a[3];}a[N],z[N];
Matrix operator * (const Matrix &x,const Matrix &y)
{
Matrix res;
for(int i=0;i<3;++i) for(int j=0;j<3;++j)
res.a[i][j]=(1ll*x.a[i][0]*y.a[0][j]+1ll*x.a[i][1]*y.a[1][j]+1ll*x.a[i][2]*y.a[2][j])%MOD;
return res;
}
Vector operator * (const Matrix &x,const Vector &y)
{
Vector res;
for(int i=0;i<3;++i)
res.a[i]=(1ll*x.a[i][0]*y.a[0]+1ll*x.a[i][1]*y.a[1]+1ll*x.a[i][2]*y.a[2])%MOD;
return res;
}
Matrix f1(Vector x)
{return (Matrix) {{{0,MOD-x.a[2],x.a[1]},{x.a[2],0,MOD-x.a[0]},{MOD-x.a[1],x.a[0],0}}};}
Matrix f2(Vector x)
{return (Matrix) {{{0,x.a[2],MOD-x.a[1]},{MOD-x.a[2],0,x.a[0]},{x.a[1],MOD-x.a[0],0}}};}
bool f(int u) {return u==ch[pt[u].fa][1];}
void dfs1(int u,int f)
{
pt[u].fa=f;pt[u].dep=pt[f].dep+1;pt[u].sz=1;
if(!ch[u][0]) return;dfs1(ch[u][0],u);dfs1(ch[u][1],u);
pt[u].sz+=pt[ch[u][0]].sz+pt[ch[u][1]].sz;
pt[u].hv=ch[u][pt[ch[u][0]].sz<pt[ch[u][1]].sz];
}
void dfs2(int u,int f)
{
pt[u].top=f;pt[f].bot=u;if(!ch[u][0]) return;ord[pt[u].dfn=++dfsT]=u;
dfs2(ch[u][0],ch[u][0]==pt[u].hv?f:ch[u][0]);
dfs2(ch[u][1],ch[u][1]==pt[u].hv?f:ch[u][1]);
}
void pu(int p) {sg[p]=sg[p*2]*sg[p*2+1];}
void upd(int p,int l,int r,int x,Matrix vl)
{
if(l==r) {sg[p]=vl;return;}
if(x<=mid) upd(p*2,l,mid,x,vl);else upd(p*2+1,mid+1,r,x,vl);pu(p);
}
void qry(int p,int l,int r,int qL,int qR,Vector &vl)
{
if(l>qR || r<qL) return;if(l>=qL && r<=qR) {vl=sg[p]*vl;return;}
qry(p*2+1,mid+1,r,qL,qR,vl);qry(p*2,l,mid,qL,qR,vl);
}
Vector qry1(int u)
{
if(!ch[u][0]) return z[u];Vector vl=z[pt[u].bot];
qry(1,1,n,pt[u].dfn,pt[pt[pt[u].bot].fa].dfn,vl);return vl;
}
void upd1(int u,Vector vl)
{
z[u]=vl;
while(u)
{
int t=pt[u].top;u=pt[t].fa;vl=qry1(t);
if(u) upd(1,1,n,pt[u].dfn,f(t)?f2(vl):f1(vl));
}
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i)
{
char op[2];scanf("%s",op);
if(op[0]=='x') scanf("%d %d",&ch[i][0],&ch[i][1]);
if(op[0]=='v') scanf("%d %d %d",&a[i].a[0],&a[i].a[1],&a[i].a[2]);
}dfs1(1,0);dfs2(1,1);for(int i=1;i<=n;++i) pt[i].bot=pt[pt[i].top].bot;
for(int i=1;i<=n;++i) if(!ch[i][0]) upd1(i,a[i]);
for(int i=1,u;i<=m;++i)
{
Vector vl;scanf("%d %d %d %d",&u,&vl.a[0],&vl.a[1],&vl.a[2]);
upd1(u,vl);vl=qry1(1);printf("%d %d %d\n",vl.a[0],vl.a[1],vl.a[2]);
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11992kb
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:
998244351 0 2 1 998244351 998244352 0 0 0
result:
ok 9 numbers
Test #2:
score: -100
Wrong Answer
time: 972ms
memory: 28452kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ by non-multiple of MOD, - expected: '393120558', found: '0'