UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214579#2376. 树与异或wangyaxu12302386ms87108kbC++111.4kb2024-11-20 18:59:082024-11-20 23:01:04

answer

#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
const int N=2e6+10,mod=1e9+7;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,q,val[N],f[N][4],fa[N],head[N],pos=0,ans=0;
struct mm{
	int next,to;
}e[N];
void add(int x,int y){
	pos++;
	e[pos].to=y;
	e[pos].next=head[x];
	head[x]=pos;
}
void dfs1(int x,int ff){
	fa[x]=ff;
	f[x][0]=val[x];
	f[x][1]=val[x];
	f[x][2]=val[x];
	for(int i=head[x];i;i=e[i].next){
		int to=e[i].to;
		if(to==ff)
		continue;
		dfs1(to,x);
		for(int j=1;j<=2;j++)
		f[x][j]^=f[to][j-1];
	}
}
void change(int x,int v){
	f[x][0]^=val[x];
	f[x][1]^=val[x];
	f[x][2]^=val[x];
	f[fa[x]][1]^=val[x];
	f[fa[x]][2]^=val[x];
	f[fa[fa[x]]][2]^=val[x];
	f[x][0]^=v;
	f[x][1]^=v;
	f[x][2]^=v;
	f[fa[x]][1]^=v;
	f[fa[x]][2]^=v;
	f[fa[fa[x]]][2]^=v;
	val[x]=v;
}
int query(int x){
	int anss=0;
	anss^=f[x][2];
	anss^=f[fa[x]][1];
	anss^=f[fa[fa[x]]][0];
	anss^=f[x][0];
	return anss;
}
signed main(){
	n=read();
	q=read();
	for(int i=1;i<=n;i++)
	val[i]=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dfs1(1,0);
	for(int i=1;i<=q;i++){
		int x=read(),v=read();
		change(x,v);
		ans+=query(x)*i%mod*i%mod;
	}
	cout<<ans;
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

1000 994
780089107 4670366 871010085 73730768 526852049 572589363 885190993 1049357301 450850404 460...

output:

491121592347

result:

wrong answer 1st numbers differ - expected: '503748432', found: '491121592347'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1260kb

input:

1000 999
26885995 181771373 378079250 245122183 660787775 479226046 575400611 257120086 214404794 48...

output:

484301022401

result:

wrong answer 1st numbers differ - expected: '301019013', found: '484301022401'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 1264kb

input:

1000 994
978408146 31636243 945016735 512129400 92881624 689719983 649699545 964802847 100094796 941...

output:

505971940839

result:

wrong answer 1st numbers differ - expected: '250985726', found: '505971940839'

Test #4:

score: 0
Wrong Answer
time: 29ms
memory: 9768kb

input:

100000 99994
194640838 777315353 114710204 754050649 372592717 210279787 542056883 638262010 7998293...

output:

49798058661800

result:

wrong answer 1st numbers differ - expected: '897014293', found: '49798058661800'

Test #5:

score: 0
Wrong Answer
time: 42ms
memory: 9768kb

input:

100000 100000
458877901 215980825 777376132 863774865 34430451 828397116 94813690 931300514 10548367...

output:

49852351799482

result:

wrong answer 1st numbers differ - expected: '351450518', found: '49852351799482'

Test #6:

score: 0
Wrong Answer
time: 37ms
memory: 9768kb

input:

100000 99991
56406146 757409402 876799234 573444553 883023109 326033134 328116703 623771278 41269529...

output:

49770440538015

result:

wrong answer 1st numbers differ - expected: '440189625', found: '49770440538015'

Test #7:

score: 0
Wrong Answer
time: 549ms
memory: 87108kb

input:

1000000 999998
814298729 663807029 628693441 45635199 148428014 913833778 1034283337 600802841 58045...

output:

500120785099019

result:

wrong answer 1st numbers differ - expected: '447637970', found: '500120785099019'

Test #8:

score: 0
Wrong Answer
time: 572ms
memory: 87108kb

input:

1000000 999993
112899321 425466951 471078924 857561298 449437156 710041336 1033281580 23390934 44420...

output:

500271453215761

result:

wrong answer 1st numbers differ - expected: '449713864', found: '500271453215761'

Test #9:

score: 0
Wrong Answer
time: 555ms
memory: 87108kb

input:

1000000 1000000
273043260 1042513348 30746190 864557483 187812119 562837674 263192174 364182254 3537...

output:

500127431239203

result:

wrong answer 1st numbers differ - expected: '922464355', found: '500127431239203'

Test #10:

score: 0
Wrong Answer
time: 602ms
memory: 87108kb

input:

1000000 999995
83067658 1064735371 623243759 757522311 539363923 924297206 75317137 543750195 822898...

output:

499741119808269

result:

wrong answer 1st numbers differ - expected: '318242296', found: '499741119808269'