10673 | 2024-04-07 21:09:24 | 111 | XORfa visszatér | cpp17 | Accepted 100/100 | 402ms | 83216 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Trie{
vector<array<int,2>>t;
vector<int>c;
Trie():t(1),c(1){
}
void add(int x){
int y=0;
for(int i=30;i>=0;i--){
int b=x>>i&1;
if(!t[y][b]){
t[y][b]=t.size();
t.emplace_back();
c.emplace_back();
}
y=t[y][b];
c[y]++;
}
}
void rem(int x){
int y=0;
for(int i=30;i>=0;i--){
int b=x>>i&1;
y=t[y][b];
c[y]--;
}
}
int get(int x){
int y=0;
int z=0;
for(int i=30;i>=0;i--){
int b=x>>i&1;
if(c[t[y][b^1]]){
y=t[y][b^1];
z|=1<<i;
}
else{
y=t[y][b];
}
}
return z;
}
};
int ans[50000];
Trie t;
struct ST{
int n;
vector<vector<int>>d;
ST(int n):n(n),d(n*4){
}
void update(int i,int l,int r,int ll,int rr,int xx){
if(l>rr||r<ll){
return;
}
if(l>=ll&&r<=rr){
d[i].push_back(xx);
return;
}
update(i*2+1,l,(l+r)/2,ll,rr,xx);
update(i*2+2,(l+r)/2+1,r,ll,rr,xx);
}
void query(int i,int l,int r,int b){
for(int x:d[i]){
t.add(x);
b=max(b,t.get(x));
}
if(l==r){
ans[l]=b;
}
if(l!=r){
query(i*2+1,l,(l+r)/2,b);
query(i*2+2,(l+r)/2+1,r,b);
}
for(int x:d[i]){
t.rem(x);
}
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,Q;
cin>>N>>Q;
vector<vector<pair<int,int>>>g(N+1);
for(int i=0;i<N-1;i++){
int a,b,w;
cin>>a>>b>>w;
g[a].emplace_back(b,w);
g[b].emplace_back(a,w);
}
vector<int>v(N+1);
auto dfs=[&](auto self,int i,int p,int x)->void{
v[i]=x;
for(auto[j,w]:g[i]){
if(j==p){
continue;
}
self(self,j,i,x^w);
}
};
dfs(dfs,1,0,0);
vector<int>s(N+1,-1);
ST st(Q);
for(int i=0;i<Q;i++){
int x;
cin>>x;
if(s[x]==-1){
s[x]=i;
}
else{
st.update(0,0,Q-1,s[x],i-1,v[x]);
s[x]=-1;
}
}
for(int x=1;x<=N;x++){
if(s[x]!=-1){
st.update(0,0,Q-1,s[x],Q-1,v[x]);
}
}
st.query(0,0,Q-1,0);
for(int i=0;i<Q;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2064 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 3ms | 2224 KiB | ||||
4 | Accepted | 3ms | 2476 KiB | ||||
5 | Accepted | 3ms | 2692 KiB | ||||
6 | Accepted | 3ms | 2948 KiB | ||||
7 | Accepted | 3ms | 3120 KiB | ||||
8 | Accepted | 3ms | 3340 KiB | ||||
9 | Accepted | 3ms | 3336 KiB | ||||
10 | Accepted | 3ms | 3320 KiB | ||||
11 | Accepted | 3ms | 3636 KiB | ||||
12 | Accepted | 3ms | 3884 KiB | ||||
13 | Accepted | 3ms | 3732 KiB | ||||
subtask3 | 13/13 | ||||||
14 | Accepted | 75ms | 25620 KiB | ||||
15 | Accepted | 79ms | 26124 KiB | ||||
16 | Accepted | 158ms | 31700 KiB | ||||
17 | Accepted | 175ms | 33480 KiB | ||||
18 | Accepted | 187ms | 33416 KiB | ||||
19 | Accepted | 186ms | 33360 KiB | ||||
20 | Accepted | 168ms | 33572 KiB | ||||
21 | Accepted | 182ms | 34064 KiB | ||||
22 | Accepted | 79ms | 27108 KiB | ||||
23 | Accepted | 79ms | 27112 KiB | ||||
subtask4 | 17/17 | ||||||
24 | Accepted | 6ms | 5968 KiB | ||||
25 | Accepted | 4ms | 5844 KiB | ||||
26 | Accepted | 6ms | 6012 KiB | ||||
27 | Accepted | 7ms | 6488 KiB | ||||
28 | Accepted | 7ms | 6492 KiB | ||||
29 | Accepted | 6ms | 5844 KiB | ||||
30 | Accepted | 6ms | 5992 KiB | ||||
31 | Accepted | 6ms | 5848 KiB | ||||
32 | Accepted | 4ms | 5324 KiB | ||||
33 | Accepted | 4ms | 5280 KiB | ||||
34 | Accepted | 4ms | 5072 KiB | ||||
35 | Accepted | 4ms | 5068 KiB | ||||
subtask5 | 59/59 | ||||||
36 | Accepted | 331ms | 62924 KiB | ||||
37 | Accepted | 273ms | 58472 KiB | ||||
38 | Accepted | 358ms | 82448 KiB | ||||
39 | Accepted | 386ms | 82316 KiB | ||||
40 | Accepted | 402ms | 83216 KiB | ||||
41 | Accepted | 298ms | 62488 KiB | ||||
42 | Accepted | 310ms | 62764 KiB | ||||
43 | Accepted | 308ms | 62836 KiB | ||||
44 | Accepted | 312ms | 62488 KiB | ||||
45 | Accepted | 174ms | 53236 KiB | ||||
46 | Accepted | 193ms | 34580 KiB | ||||
47 | Accepted | 193ms | 34724 KiB | ||||
48 | Accepted | 192ms | 34620 KiB | ||||
49 | Accepted | 192ms | 34616 KiB |