QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593358#8133. When Anton Saw This Task He Reacted With 😩2020HZ06WA 2323ms94652kbC++142.6kb2024-09-27 13:29:412024-09-27 13:29:43

Judging History

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

  • [2024-09-27 13:29:43]
  • 评测
  • 测评结果:WA
  • 用时:2323ms
  • 内存:94652kb
  • [2024-09-27 13:29:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X v[x].a[0][0]
#define Y v[x].a[1][0]
#define Z v[x].a[2][0]
#define mid (l+r)/2
#define ls rt*2
#define rs rt*2+1
const ll mod=998244353;
int n,q,l[200005],r[200005],siz[200005],top[200005],dfn[200005],tim,fa[200005],p[200005],bot[200005];
struct mat{
	ll a[3][3];
	mat(){
		memset(a,0,sizeof(a));
	}
	void g(){
		for(int i=0;i<3;i++) a[i][i]=1;
	}
	mat operator *(const mat &x)const{
		mat res;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++)
					(res.a[i][j]+=a[i][k]*x.a[k][j]%mod)%=mod;
		return res;
	}
}v[200005],M[200005],tr[800005];
bool tag[200005];
void dfs1(int u){
	siz[u]=1;
	if(l[u]){
		dfs1(l[u]),siz[u]+=siz[l[u]];
		dfs1(r[u]),siz[u]+=siz[r[u]];
		if(siz[l[u]]<siz[r[u]]) swap(l[u],r[u]),tag[u]=1;
	}
}
void dfs2(int u,int t){
	top[u]=t;dfn[u]=++tim;p[dfn[u]]=u,bot[t]=u;
	if(l[u]){
		dfs2(l[u],t),dfs2(r[u],r[u]);
		int x=r[u];
		ll tmp[3][3]={0,Z,(mod-Y)%mod,(mod-Z)%mod,0,X,Y,(mod-X)%mod,0};
		memcpy(M[u].a,tmp,sizeof(tmp));
		v[u]=M[u]*v[l[u]];
	}else M[u]=v[u];
}
void dfs3(int u){
	if(l[u]) tag[l[u]]^=tag[u],tag[r[u]]^=tag[u],dfs3(l[u]),dfs3(r[u]);
}
void build(int l,int r,int rt){
	if(l==r){
		tr[rt]=M[p[l]];
		return;
	} 
	build(l,mid,ls),build(mid+1,r,rs);
	tr[rt]=tr[ls]*tr[rs];
}
void modify(int l,int r,int rt,int pos){
	if(l==r){
		tr[rt]=M[p[l]];
		return;
	} 
	if(pos<=mid) modify(l,mid,ls,pos);
	else modify(mid+1,r,rs,pos);
	tr[rt]=tr[ls]*tr[rs];
}
mat query(int l,int r,int rt,int L,int R){
	if(l>=L&&r<=R) return tr[rt];
	mat res;res.g();
	if(L<=mid) res=res*query(l,mid,ls,L,R);
	if(R>mid) res=res*query(mid+1,r,rs,L,R);
	return res;
}
int main(){
	int x,y;
	char s[3];
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%s",s);
		if(s[0]=='x'){
			scanf("%d%d",&x,&y);
			l[i]=x,r[i]=y;fa[x]=fa[y]=i;
		}
		else scanf("%lld%lld%lld",&v[i].a[0][0],&v[i].a[1][0],&v[i].a[2][0]);
	}
	dfs1(1);
	dfs2(1,1);
	dfs3(1);
	build(1,n,1);
	while(q--){
		scanf("%d",&x);
		scanf("%lld%lld%lld",&X,&Y,&Z);
		ll mul;
		if(tag[x]==1) mul=-1;
		else mul=1;
		M[x]=v[x],modify(1,n,1,dfn[x]);
		mat res;
		while(fa[top[x]]){
			int u=fa[top[x]];
			v[x]=query(1,n,1,dfn[top[x]],dfn[bot[top[x]]]);
			ll tmp[3][3]={0,Z,(mod-Y)%mod,(mod-Z)%mod,0,X,Y,(mod-X)%mod,0};
			memcpy(M[u].a,tmp,sizeof(tmp));
			modify(1,n,1,dfn[u]);
			x=u;
		}
		res=query(1,n,1,1,dfn[bot[1]]);
		printf("%lld %lld %lld\n",(res.a[0][0]*mul+mod)%mod,(res.a[1][0]*mul+mod)%mod,(res.a[2][0]*mul+mod)%mod);
	}
	return 0;
}

详细

Test #1:

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

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: 2323ms
memory: 94652kb

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:

605123795 224477738 610947005
759959566 981774500 128012497
703632542 18232745 464602324
593864779 252947501 944750793
593678852 169374593 920223197
405749495 350493049 116816620
808225886 483001218 480063798
370063853 488259799 740814218
984507108 646156562 80833866
932051309 366591227 479931477
79...

result:

wrong answer 1st numbers differ by non-multiple of MOD, - expected: '393120558', found: '605123795'