#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using tupiii=tuple<int,int,int>;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
int main(){
_3qplfh5;
int q;
cin>>q;
vec(tupiii) qry;
int n=1;
rep(_,q){
string s;
cin>>s;
int t=0;
if(s=="Add"){
t=1;
n++;
}
int _a,_b;
cin>>_a>>_b;
qry.pb({t,_a,_b});
}
vec(vec(pii)) adj(n);
int now=1;
for(auto [t,_a,_b] : qry){
if(t==1){
adj[_a-1].pb({now,_b});
adj[now].pb({_a-1,_b});
now++;
}
}
//rabbit tour
vi tour;
vi tin(n,0),tout(n,0);
vi psum(n,0);
int tm=0;
auto dfs=[&](auto self,int v,int par)->void{
tin[v]=tm++;
tour.pb(v);
for(auto edge : adj[v]){
int u=edge.fi;
if(u!=par){
psum[u]=psum[v]^edge.se;
// cout<<edge.se<<"\n";
self(self,u,v);
}
}
tout[v]=tm++;
tour.pb(v);
};
dfs(dfs,0,-1);
vec(std::map<ll,vi>) rbts(32);
rep(j,31){
rbts[j][0].pb(tin[0]);
}
now=1;
for(auto [t,_a,_b] : qry){
if(t==0){
_a--,_b--;
int k=psum[_a];
int need=0;
int ans=0;
drep(j,31){
if(!(k&(1<<j))){
need|=(1<<j);
}
bool pokita=0;
if(rbts[j].find(need)!=rbts[j].end()){
auto it=lower_bound(all(rbts[j][need]),tin[_b]);
if(it!=rbts[j][need].end() and *it<tout[_b]){
pokita=1;
}
}
if(not pokita){
if(!(k&(1<<j))) need^=(1<<j);
else need|=(1<<j);
}
}
ans=need^k;
cout<<ans<<"\n";
}else{
int v=now;
int wata=0;
drep(j,31){
if(psum[v]&(1<<j)) wata|=(1<<j);
rbts[j][wata].pb(tin[v]);
sort(all(rbts[j][wata]));
}
now++;
}
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
9 ms |
1356 KB |
Output is correct |
14 |
Correct |
14 ms |
2328 KB |
Output is correct |
15 |
Correct |
23 ms |
3304 KB |
Output is correct |
16 |
Correct |
33 ms |
4192 KB |
Output is correct |
17 |
Correct |
10 ms |
1356 KB |
Output is correct |
18 |
Correct |
22 ms |
2224 KB |
Output is correct |
19 |
Correct |
44 ms |
3204 KB |
Output is correct |
20 |
Correct |
78 ms |
4012 KB |
Output is correct |
21 |
Correct |
10 ms |
1356 KB |
Output is correct |
22 |
Correct |
24 ms |
2320 KB |
Output is correct |
23 |
Correct |
31 ms |
3240 KB |
Output is correct |
24 |
Correct |
52 ms |
4012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5071 ms |
48572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
9 ms |
1356 KB |
Output is correct |
14 |
Correct |
14 ms |
2328 KB |
Output is correct |
15 |
Correct |
23 ms |
3304 KB |
Output is correct |
16 |
Correct |
33 ms |
4192 KB |
Output is correct |
17 |
Correct |
10 ms |
1356 KB |
Output is correct |
18 |
Correct |
22 ms |
2224 KB |
Output is correct |
19 |
Correct |
44 ms |
3204 KB |
Output is correct |
20 |
Correct |
78 ms |
4012 KB |
Output is correct |
21 |
Correct |
10 ms |
1356 KB |
Output is correct |
22 |
Correct |
24 ms |
2320 KB |
Output is correct |
23 |
Correct |
31 ms |
3240 KB |
Output is correct |
24 |
Correct |
52 ms |
4012 KB |
Output is correct |
25 |
Execution timed out |
5071 ms |
48572 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |