QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309343#8133. When Anton Saw This Task He Reacted With 😩ucup-team266#WA 739ms52676kbC++233.7kb2024-01-20 16:47:442024-01-20 16:47:44

Judging History

你现在查看的是最新测评结果

  • [2024-01-20 16:47:44]
  • 评测
  • 测评结果:WA
  • 用时:739ms
  • 内存:52676kb
  • [2024-01-20 16:47:44]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
int ls[200200],rs[200200];
array<ll,3> val[200200];
array<ll,3> cross(array<ll,3> A,array<ll,3> B)
{
	return {(A[1]*B[2]-A[2]*B[1])%mod,(A[2]*B[0]-A[0]*B[2])%mod,(A[0]*B[1]-A[1]*B[0])%mod};
}
int siz[200200],son[200200],depth[200200],tp[200200],fa[200200],dfn[200200],down[200200],tot;
void dfs1(int u)
{
	siz[u]=1;
	if(ls[u])
	{
		depth[ls[u]]=depth[rs[u]]=depth[u]+1;
		fa[ls[u]]=fa[rs[u]]=u;
		dfs1(ls[u]);
		dfs1(rs[u]);
		siz[u]+=siz[ls[u]]+siz[rs[u]];
		if(siz[ls[u]]>siz[rs[u]])
			son[u]=ls[u];
		else
			son[u]=rs[u];
	}
}
void dfs2(int u)
{
	dfn[u]=++tot;
	if(!tp[u])
		tp[u]=u;
	down[tp[u]]=u;
	if(son[u])
	{
		tp[son[u]]=tp[u];
		dfs2(son[u]);
		dfs2(ls[u]+rs[u]-son[u]);
	}
}
using matrix=array<array<ll,3>,3>;
matrix mul(matrix a,matrix b)
{
	matrix ans;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			ans[i][j]=0;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++)
				ans[i][k]+=a[i][j]*b[j][k];
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			ans[i][j]%=mod;
	return ans;
}
matrix lget(array<ll,3> val)
{
	return
	{
		array<ll,3>{0,val[2],-val[1]},
		array<ll,3>{-val[2],0,val[0]},
		array<ll,3>{val[1],-val[0],0}
	};
}
matrix rget(array<ll,3> val)
{
	return
	{
		array<ll,3>{0,-val[2],val[1]},
		array<ll,3>{val[2],0,-val[0]},
		array<ll,3>{-val[1],val[0],0}
	};
}
matrix seg[200200<<2];
void update(int x,int l,int r,int p,matrix m)
{
	if(l==r)
	{
		seg[x]=m;
		return ;
	}
	int mid=(l+r)/2;
	if(p<=mid)
		update(x<<1,l,mid,p,m);
	else
		update((x<<1)|1,mid+1,r,p,m);
	seg[x]=mul(seg[(x<<1)|1],seg[x<<1]);
}
matrix query(int x,int l,int r,int ql,int qr)
{
	if(ql>qr) return {array<ll,3>{1,0,0},array<ll,3>{0,1,0},array<ll,3>{0,0,1}};
	if(l==ql&&r==qr)
		return seg[x];
	int mid=(l+r)/2;
	if(qr<=mid)
		return query(x<<1,l,mid,ql,qr);
	if(ql>mid)
		return query((x<<1)|1,mid+1,r,ql,qr);
	return mul(query((x<<1)|1,mid+1,r,mid+1,qr),query(x<<1,l,mid,ql,mid));
}
int n,q;
void refresh(int u)
{
	int f=fa[u];
	if(!f) return ;
	update(1,1,n,dfn[f],(u==ls[f])?lget(val[u]):rget(val[u]));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		char ch;
		cin>>ch;
		if(ch=='x')
			cin>>ls[i]>>rs[i];
		else
			cin>>val[i][0]>>val[i][1]>>val[i][2];
	}
	dfs1(1);
	dfs2(1);
	for(int i=n;i>=1;i--)
		if(ls[i])
			val[i]=cross(val[ls[i]],val[rs[i]]);
	for(int i=n;i>=1;i--)
		if(tp[i]==i)
			refresh(i);
	while(q--)
	{
		int u;
		array<ll,3> v;
		cin>>u>>v[0]>>v[1]>>v[2];
		val[u]=v;
		while(u)
		{
			int x=tp[u];
			u=down[x];
			matrix mat=query(1,1,n,dfn[x],dfn[u]-1);
			val[x]=
			{
				(val[u][0]*mat[0][0]+val[u][1]*mat[1][0]+val[u][2]*mat[2][0])%mod,
				(val[u][0]*mat[0][1]+val[u][1]*mat[1][1]+val[u][2]*mat[2][1])%mod,
				(val[u][0]*mat[0][2]+val[u][1]*mat[1][2]+val[u][2]*mat[2][2])%mod
			};
			refresh(x);
			u=fa[x];
		}
		cout<<val[1][0]<<" "<<val[1][1]<<" "<<val[1][2]<<'\n';
	}
	return 0;
}
/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9764kb

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: -100
Wrong Answer
time: 739ms
memory: 52676kb

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'