ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214623 | #2376. 树与异或 | erican | 100 | 4525ms | 131656kb | C++11 | 2.3kb | 2024-11-20 20:54:52 | 2024-11-20 23:06:47 |
answer
/* Erica N */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
int xx = 0, ff = 1;char ch = getchar();
while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
return xx * ff;
}
// void write(int out) {
// if (out < 0)
// putchar('-'), out = -out;
// if (out > 9)
// write(out / 10);
// putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
const int N = 2e6 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;
int fa[N],g[N];
int a[N];
int f[N];//节点x的儿子的异或和
vector<int> e[N];
void add(int a,int b){
e[a].pb(b);
e[b].pb(a);
}
void dfs(int x,int ft){
fa[x]=ft;
f[x]=a[x];
for(auto v:e[x]){
if(v==ft)continue;
f[x]^=a[v];
dfs(v,x);
}
}
void dfs2(int x,int ft){
g[x]^=f[fa[x]];
g[x]^=a[fa[fa[x]]];
for(auto v:e[x]){
if(v==ft)continue;
g[x]^=f[v];
dfs2(v,x);
}
}
int tag[N],tag2[N];
signed main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n=rd,q=rd;
for(int i=1;i<=n;i++){
a[i]=rd;
}
for(int i=1;i<n;i++){
add(rd,rd);
}
add(n+1,1);
add(n+2,n+1);
// f[0]=a[1];
dfs(n+2,0);
dfs2(n+2,0);
int ans=0;
// for(int i=1;i<=n;i++)cdbg(f[i]);
// for(int i=1;i<=n;i++)cdbg(g[i]);
for(int i=1;i<=q;i++){
int x=rd,v=rd;
// w[x]=v;
tag2[x]^=a[x]^v;
tag[fa[x]]^=a[x]^v;
g[fa[fa[x]]]^=a[x]^v;
g[fa[x]]^=a[x]^v;
int res=g[x]^tag[fa[x]]^tag2[fa[x]]^tag2[fa[fa[x]]];
a[x]=v;
ans=(ans+res*i%MOD*i%MOD)%MOD;
}
cout<<ans<<endl;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 8ms
memory: 48188kb
input:
1000 994 780089107 4670366 871010085 73730768 526852049 572589363 885190993 1049357301 450850404 460...
output:
503748432
result:
ok 1 number(s): "503748432"
Test #2:
score: 10
Accepted
time: 8ms
memory: 48188kb
input:
1000 999 26885995 181771373 378079250 245122183 660787775 479226046 575400611 257120086 214404794 48...
output:
301019013
result:
ok 1 number(s): "301019013"
Test #3:
score: 10
Accepted
time: 4ms
memory: 48192kb
input:
1000 994 978408146 31636243 945016735 512129400 92881624 689719983 649699545 964802847 100094796 941...
output:
250985726
result:
ok 1 number(s): "250985726"
Test #4:
score: 10
Accepted
time: 64ms
memory: 56312kb
input:
100000 99994 194640838 777315353 114710204 754050649 372592717 210279787 542056883 638262010 7998293...
output:
897014293
result:
ok 1 number(s): "897014293"
Test #5:
score: 10
Accepted
time: 56ms
memory: 56304kb
input:
100000 100000 458877901 215980825 777376132 863774865 34430451 828397116 94813690 931300514 10548367...
output:
351450518
result:
ok 1 number(s): "351450518"
Test #6:
score: 10
Accepted
time: 55ms
memory: 56420kb
input:
100000 99991 56406146 757409402 876799234 573444553 883023109 326033134 328116703 623771278 41269529...
output:
440189625
result:
ok 1 number(s): "440189625"
Test #7:
score: 10
Accepted
time: 1080ms
memory: 131636kb
input:
1000000 999998 814298729 663807029 628693441 45635199 148428014 913833778 1034283337 600802841 58045...
output:
447637970
result:
ok 1 number(s): "447637970"
Test #8:
score: 10
Accepted
time: 1074ms
memory: 131656kb
input:
1000000 999993 112899321 425466951 471078924 857561298 449437156 710041336 1033281580 23390934 44420...
output:
449713864
result:
ok 1 number(s): "449713864"
Test #9:
score: 10
Accepted
time: 1026ms
memory: 131632kb
input:
1000000 1000000 273043260 1042513348 30746190 864557483 187812119 562837674 263192174 364182254 3537...
output:
922464355
result:
ok 1 number(s): "922464355"
Test #10:
score: 10
Accepted
time: 1150ms
memory: 131624kb
input:
1000000 999995 83067658 1064735371 623243759 757522311 539363923 924297206 75317137 543750195 822898...
output:
318242296
result:
ok 1 number(s): "318242296"
Extra Test:
score: 0
Extra Test Passed