10667 | 2024-04-07 19:58:58 | 111 | XORfa visszatér | cpp17 | Time limit exceeded 11/100 | 1.583s | 522372 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Trie{
vector<array<int,2>>t;
int b;
Trie():t(1),b(0){
}
void add(int x){
if(t.size()>1){
b=max(b,get(x));
}
int y=0;
for(int i=30;i>=0;i--){
int b=x>>i&1;
if(t[y][b]==0){
t[y][b]=t.size();
t.emplace_back();
}
y=t[y][b];
}
}
int get(int x){
int y=0;
int z=0;
for(int i=30;i>=0;i--){
int b=x>>i&1;
if(t[y][b^1]){
y=t[y][b^1];
z^=1<<i;
}
else{
y=t[y][b];
}
}
return z;
}
};
struct ST{
int n;
vector<Trie>t;
ST(int n):n(n),t(n*4){
}
void update(int i,int l,int r,int ll,int rr,int xx){
if(r<ll||l>rr){
return;
}
t[i].add(xx);
if(l==r){
return;
}
update(i*2+1,l,(l+r)/2,ll,rr,xx);
update(i*2+2,(l+r)/2+1,r,ll,rr,xx);
}
int query(int i,int l,int r,int pp){
if(r<pp||l>pp){
return 0;
}
if(l==r){
return t[i].b;
}
return max(query(i*2+1,l,(l+r)/2,pp),query(i*2+2,(l+r)/2+1,r,pp));
}
};
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]);
}
}
for(int i=0;i<Q;i++){
cout<<st.query(0,0,Q-1,i)<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1964 KiB | ||||
2 | Accepted | 3ms | 2112 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 6ms | 7372 KiB | ||||
4 | Accepted | 4ms | 5808 KiB | ||||
5 | Accepted | 8ms | 10748 KiB | ||||
6 | Accepted | 6ms | 8440 KiB | ||||
7 | Accepted | 6ms | 7600 KiB | ||||
8 | Accepted | 7ms | 10080 KiB | ||||
9 | Accepted | 6ms | 7868 KiB | ||||
10 | Accepted | 4ms | 3900 KiB | ||||
11 | Accepted | 4ms | 3912 KiB | ||||
12 | Accepted | 4ms | 3908 KiB | ||||
13 | Accepted | 4ms | 4032 KiB | ||||
subtask3 | 0/13 | ||||||
14 | Accepted | 282ms | 184420 KiB | ||||
15 | Accepted | 337ms | 204232 KiB | ||||
16 | Time limit exceeded | 1.569s | 36852 KiB | ||||
17 | Time limit exceeded | 1.583s | 37924 KiB | ||||
18 | Time limit exceeded | 1.564s | 43316 KiB | ||||
19 | Time limit exceeded | 1.577s | 54004 KiB | ||||
20 | Time limit exceeded | 1.569s | 36096 KiB | ||||
21 | Time limit exceeded | 1.572s | 38316 KiB | ||||
22 | Accepted | 370ms | 204828 KiB | ||||
23 | Accepted | 342ms | 205072 KiB | ||||
subtask4 | 0/17 | ||||||
24 | Accepted | 523ms | 374572 KiB | ||||
25 | Accepted | 209ms | 186456 KiB | ||||
26 | Accepted | 896ms | 498860 KiB | ||||
27 | Runtime error | 1.319s | 522372 KiB | ||||
28 | Runtime error | 980ms | 522328 KiB | ||||
29 | Accepted | 437ms | 318892 KiB | ||||
30 | Accepted | 791ms | 415152 KiB | ||||
31 | Accepted | 596ms | 414656 KiB | ||||
32 | Accepted | 279ms | 32852 KiB | ||||
33 | Accepted | 275ms | 32916 KiB | ||||
34 | Accepted | 284ms | 33252 KiB | ||||
35 | Accepted | 284ms | 33336 KiB | ||||
subtask5 | 0/59 | ||||||
36 | Runtime error | 730ms | 521820 KiB | ||||
37 | Runtime error | 927ms | 521784 KiB | ||||
38 | Runtime error | 689ms | 521744 KiB | ||||
39 | Runtime error | 679ms | 521780 KiB | ||||
40 | Runtime error | 865ms | 521756 KiB | ||||
41 | Runtime error | 728ms | 521716 KiB | ||||
42 | Runtime error | 955ms | 521712 KiB | ||||
43 | Runtime error | 722ms | 521704 KiB | ||||
44 | Runtime error | 948ms | 521620 KiB | ||||
45 | Runtime error | 505ms | 521640 KiB | ||||
46 | Time limit exceeded | 1.552s | 188932 KiB | ||||
47 | Time limit exceeded | 1.583s | 189040 KiB | ||||
48 | Time limit exceeded | 1.574s | 189072 KiB | ||||
49 | Time limit exceeded | 1.583s | 188984 KiB |