10668 | 2024-04-07 20:14:39 | 111 | XORfa visszatér | cpp17 | Time limit exceeded 11/100 | 1.588s | 522560 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]){
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&&r<=l){
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;
}
int ans=0;
if(l==r){
return t[i].b;
}
ans=max(ans,query(i*2+1,l,(l+r)/2,pp));
ans=max(ans,query(i*2+2,(l+r)/2+1,r,pp));
return ans;
}
};
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 | 1832 KiB | ||||
2 | Accepted | 3ms | 2064 KiB | ||||
subtask2 | 11/11 | ||||||
3 | Accepted | 6ms | 7324 KiB | ||||
4 | Accepted | 4ms | 5744 KiB | ||||
5 | Accepted | 8ms | 10700 KiB | ||||
6 | Accepted | 6ms | 8648 KiB | ||||
7 | Accepted | 6ms | 7532 KiB | ||||
8 | Accepted | 8ms | 10188 KiB | ||||
9 | Accepted | 6ms | 8324 KiB | ||||
10 | Accepted | 4ms | 4200 KiB | ||||
11 | Accepted | 4ms | 4324 KiB | ||||
12 | Accepted | 4ms | 4556 KiB | ||||
13 | Accepted | 4ms | 4452 KiB | ||||
subtask3 | 0/13 | ||||||
14 | Accepted | 282ms | 185052 KiB | ||||
15 | Accepted | 337ms | 204740 KiB | ||||
16 | Time limit exceeded | 1.529s | 36940 KiB | ||||
17 | Time limit exceeded | 1.567s | 38420 KiB | ||||
18 | Time limit exceeded | 1.564s | 43764 KiB | ||||
19 | Time limit exceeded | 1.544s | 54072 KiB | ||||
20 | Time limit exceeded | 1.544s | 36260 KiB | ||||
21 | Time limit exceeded | 1.572s | 38452 KiB | ||||
22 | Accepted | 356ms | 205080 KiB | ||||
23 | Accepted | 340ms | 204972 KiB | ||||
subtask4 | 0/17 | ||||||
24 | Accepted | 529ms | 374600 KiB | ||||
25 | Accepted | 208ms | 186676 KiB | ||||
26 | Accepted | 889ms | 498924 KiB | ||||
27 | Runtime error | 970ms | 522560 KiB | ||||
28 | Runtime error | 973ms | 522512 KiB | ||||
29 | Accepted | 435ms | 318696 KiB | ||||
30 | Accepted | 586ms | 414632 KiB | ||||
31 | Accepted | 588ms | 414228 KiB | ||||
32 | Accepted | 275ms | 32492 KiB | ||||
33 | Accepted | 277ms | 32576 KiB | ||||
34 | Accepted | 277ms | 32612 KiB | ||||
35 | Accepted | 277ms | 32592 KiB | ||||
subtask5 | 0/59 | ||||||
36 | Runtime error | 736ms | 522464 KiB | ||||
37 | Runtime error | 702ms | 522436 KiB | ||||
38 | Runtime error | 680ms | 522408 KiB | ||||
39 | Runtime error | 698ms | 522444 KiB | ||||
40 | Runtime error | 646ms | 522416 KiB | ||||
41 | Runtime error | 728ms | 522380 KiB | ||||
42 | Runtime error | 720ms | 522356 KiB | ||||
43 | Runtime error | 714ms | 522348 KiB | ||||
44 | Runtime error | 722ms | 522352 KiB | ||||
45 | Runtime error | 495ms | 522368 KiB | ||||
46 | Time limit exceeded | 1.577s | 198284 KiB | ||||
47 | Time limit exceeded | 1.544s | 188380 KiB | ||||
48 | Time limit exceeded | 1.552s | 188496 KiB | ||||
49 | Time limit exceeded | 1.588s | 188524 KiB |