#include <bits/stdc++.h>
using namespace std;
#define needforspeed ios::sync_with_stdio(0);cin.tie(0);
#define int long long int
#define pb push_back
#define ins insert
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<
const int mod = 1e9 +7,sze = 2e5 +23,inf = INT_MAX, L = 31;
struct T {
T *child[2];
set<int> fener;
T(){
child[0] = child[1] = nullptr;
}
};
T *root = new T();
int tnod = 1;
vector<pair<int, int>> graph[sze];
int discover[sze], finish[sze], pref[sze];
int timer = 0;
void add(T *node, int bit, int val, int gir){
if (bit < 0) {
return;
}
int x = 0;
if(val & (1<<bit)){
x=1;
}
if(!node->child[x]) {
node->child[x] = new T();
}
node->child[x]->fener.ins(gir);
add(node->child[x], bit - 1, val, gir);
}
int qry(T *node, int bit, int val, int l, int r){
if(bit < 0) {
return 0;
}
int lazim = (val & (1 << bit)) ? 0 : 1;
if(node->child[lazim] && node->child[lazim]->fener.lower_bound(l) != node->child[lazim]->fener.upper_bound(r)){
return (1 << bit) + qry(node->child[lazim], bit - 1, val, l, r);
}
else{
return qry(node->child[1 - lazim], bit - 1, val, l, r);
}
}
void dfs(int node,int par,int px){
discover[node]=++timer;
pref[node]=px;
for(auto v:graph[node]){
if(v.first!=par){
dfs(v.first,node,px ^ v.second);
}
}
finish[node]=++timer;
}
void opt1z(){
int q;
cin>>q;
int nodec =2;
vector<pair<int, pair<int,int>>> queries;
for(int i=0;i<q;i++){
string op;cin>>op;
int a,b;
cin>>a>>b;
if(op=="Add"){
graph[a].pb({nodec,b});
graph[nodec].pb({a,b});
queries.pb({0,{nodec,b}});
nodec++;
}
else{
queries.pb({1,{a,b}});
}
}
dfs(1,-1,0);
add(root,L,0,discover[1]);
// cout<<pref[2]<<endl;
for(auto v:queries){
auto [a,b] = v.second;
if(v.first ==0){
add(root,L,pref[a],discover[a]);
}
else{
// cout<<"sa"<<endl;
cout<<qry(root,L,pref[a],discover[b],finish[b])<<endl;
}
}
}
signed main() {
needforspeed;
int tt = 1;
// cin>>tt;
while(tt--){
opt1z();
}
return 0;
}
Compilation message
klasika.cpp: In function 'void opt1z()':
klasika.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | auto [a,b] = v.second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
3 ms |
5144 KB |
Output is correct |
10 |
Correct |
3 ms |
5468 KB |
Output is correct |
11 |
Correct |
3 ms |
5468 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
3 ms |
5144 KB |
Output is correct |
10 |
Correct |
3 ms |
5468 KB |
Output is correct |
11 |
Correct |
3 ms |
5468 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
5 ms |
6488 KB |
Output is correct |
14 |
Correct |
6 ms |
7772 KB |
Output is correct |
15 |
Correct |
7 ms |
9052 KB |
Output is correct |
16 |
Correct |
9 ms |
10332 KB |
Output is correct |
17 |
Correct |
4 ms |
6492 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
7 ms |
9300 KB |
Output is correct |
20 |
Correct |
8 ms |
10076 KB |
Output is correct |
21 |
Correct |
5 ms |
6516 KB |
Output is correct |
22 |
Correct |
6 ms |
7760 KB |
Output is correct |
23 |
Correct |
10 ms |
9052 KB |
Output is correct |
24 |
Correct |
9 ms |
10076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
613 ms |
125400 KB |
Output is correct |
2 |
Correct |
927 ms |
233456 KB |
Output is correct |
3 |
Correct |
1281 ms |
340728 KB |
Output is correct |
4 |
Correct |
1520 ms |
445680 KB |
Output is correct |
5 |
Correct |
519 ms |
126628 KB |
Output is correct |
6 |
Correct |
956 ms |
233728 KB |
Output is correct |
7 |
Correct |
1326 ms |
336628 KB |
Output is correct |
8 |
Correct |
1732 ms |
439496 KB |
Output is correct |
9 |
Correct |
545 ms |
126252 KB |
Output is correct |
10 |
Correct |
886 ms |
234576 KB |
Output is correct |
11 |
Correct |
1222 ms |
338652 KB |
Output is correct |
12 |
Correct |
1569 ms |
441076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5208 KB |
Output is correct |
2 |
Correct |
3 ms |
5212 KB |
Output is correct |
3 |
Correct |
2 ms |
5468 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
2 ms |
5468 KB |
Output is correct |
8 |
Correct |
3 ms |
5736 KB |
Output is correct |
9 |
Correct |
3 ms |
5144 KB |
Output is correct |
10 |
Correct |
3 ms |
5468 KB |
Output is correct |
11 |
Correct |
3 ms |
5468 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
5 ms |
6488 KB |
Output is correct |
14 |
Correct |
6 ms |
7772 KB |
Output is correct |
15 |
Correct |
7 ms |
9052 KB |
Output is correct |
16 |
Correct |
9 ms |
10332 KB |
Output is correct |
17 |
Correct |
4 ms |
6492 KB |
Output is correct |
18 |
Correct |
9 ms |
7772 KB |
Output is correct |
19 |
Correct |
7 ms |
9300 KB |
Output is correct |
20 |
Correct |
8 ms |
10076 KB |
Output is correct |
21 |
Correct |
5 ms |
6516 KB |
Output is correct |
22 |
Correct |
6 ms |
7760 KB |
Output is correct |
23 |
Correct |
10 ms |
9052 KB |
Output is correct |
24 |
Correct |
9 ms |
10076 KB |
Output is correct |
25 |
Correct |
613 ms |
125400 KB |
Output is correct |
26 |
Correct |
927 ms |
233456 KB |
Output is correct |
27 |
Correct |
1281 ms |
340728 KB |
Output is correct |
28 |
Correct |
1520 ms |
445680 KB |
Output is correct |
29 |
Correct |
519 ms |
126628 KB |
Output is correct |
30 |
Correct |
956 ms |
233728 KB |
Output is correct |
31 |
Correct |
1326 ms |
336628 KB |
Output is correct |
32 |
Correct |
1732 ms |
439496 KB |
Output is correct |
33 |
Correct |
545 ms |
126252 KB |
Output is correct |
34 |
Correct |
886 ms |
234576 KB |
Output is correct |
35 |
Correct |
1222 ms |
338652 KB |
Output is correct |
36 |
Correct |
1569 ms |
441076 KB |
Output is correct |
37 |
Correct |
919 ms |
129240 KB |
Output is correct |
38 |
Correct |
1265 ms |
236788 KB |
Output is correct |
39 |
Correct |
1506 ms |
343536 KB |
Output is correct |
40 |
Correct |
1834 ms |
446028 KB |
Output is correct |
41 |
Correct |
949 ms |
127188 KB |
Output is correct |
42 |
Correct |
1395 ms |
233688 KB |
Output is correct |
43 |
Correct |
1619 ms |
336684 KB |
Output is correct |
44 |
Correct |
1905 ms |
438768 KB |
Output is correct |
45 |
Correct |
1064 ms |
126684 KB |
Output is correct |
46 |
Correct |
1535 ms |
234484 KB |
Output is correct |
47 |
Correct |
1742 ms |
337456 KB |
Output is correct |
48 |
Correct |
1864 ms |
440928 KB |
Output is correct |