#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 200005
const int M = 1e9 + 7;
using namespace std;
int Q, n, m, a[maxn];
vector <int> g[maxn];
struct dl{int x, y, time;}b[maxn];
int in[maxn], out[maxn], tmp;
void dfs(int u){
in[u] = ++tmp;
for(auto v: g[u]) dfs(v);
out[u] = tmp;
}
int xd[maxn*20][3], cnt;
set <int> st[maxn*20];
void add(int num, int time){
int tt = 0;
fid(i, 30, 0){
int c = getbit(num, i);
if(xd[tt][c] == 0) xd[tt][c] = ++cnt;
tt = xd[tt][c];
st[tt].insert(time);
}
}
bool check(int tt, int l, int r){
if(tt == 0) return 0;
auto it = st[tt].lower_bound(l);
if(it == st[tt].end()) return 0;
return (*it <= r) ;
}
int get(int l, int r, int num){
int tt = 0, ans = 0;
fid(i, 30, 0){
int c = getbit(num, i);
if(check(xd[tt][1 - c], l, r)){
ans += (1 << i);
tt = xd[tt][1 - c];
}
else tt = xd[tt][c];
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp", "r")){
freopen(Alora".inp", "r", stdin);
freopen(Alora".out", "w", stdout);}
cin >> Q;
n = 1;
fi(i, 1, Q){
string s; int x, y;
cin >> s >> x >> y;
if(s == "Add"){
a[++n] = a[x] ^ y;
g[x].pb(n);
b[i] = {0, n, n};
}
else b[i] = {1, x, y};
}
dfs(1);
add(0, 1);
fi(i, 1, Q){
auto[t, x, y] = b[i];
if(t == 0) add(a[x], in[x]);
else{
cout << get(in[y], out[y], a[x]) << '\n';
}
}
return 0;
}
Compilation message
klasika.cpp: In function 'int main()':
klasika.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(Alora".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(Alora".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
196688 KB |
Output is correct |
2 |
Correct |
39 ms |
196584 KB |
Output is correct |
3 |
Correct |
39 ms |
196700 KB |
Output is correct |
4 |
Correct |
38 ms |
196692 KB |
Output is correct |
5 |
Correct |
38 ms |
196692 KB |
Output is correct |
6 |
Correct |
38 ms |
196792 KB |
Output is correct |
7 |
Correct |
38 ms |
196692 KB |
Output is correct |
8 |
Correct |
38 ms |
196956 KB |
Output is correct |
9 |
Correct |
38 ms |
196700 KB |
Output is correct |
10 |
Correct |
38 ms |
196948 KB |
Output is correct |
11 |
Correct |
39 ms |
196696 KB |
Output is correct |
12 |
Correct |
39 ms |
196956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
196688 KB |
Output is correct |
2 |
Correct |
39 ms |
196584 KB |
Output is correct |
3 |
Correct |
39 ms |
196700 KB |
Output is correct |
4 |
Correct |
38 ms |
196692 KB |
Output is correct |
5 |
Correct |
38 ms |
196692 KB |
Output is correct |
6 |
Correct |
38 ms |
196792 KB |
Output is correct |
7 |
Correct |
38 ms |
196692 KB |
Output is correct |
8 |
Correct |
38 ms |
196956 KB |
Output is correct |
9 |
Correct |
38 ms |
196700 KB |
Output is correct |
10 |
Correct |
38 ms |
196948 KB |
Output is correct |
11 |
Correct |
39 ms |
196696 KB |
Output is correct |
12 |
Correct |
39 ms |
196956 KB |
Output is correct |
13 |
Correct |
40 ms |
197208 KB |
Output is correct |
14 |
Correct |
40 ms |
197980 KB |
Output is correct |
15 |
Correct |
42 ms |
198368 KB |
Output is correct |
16 |
Correct |
43 ms |
198924 KB |
Output is correct |
17 |
Correct |
40 ms |
197392 KB |
Output is correct |
18 |
Correct |
41 ms |
197712 KB |
Output is correct |
19 |
Correct |
42 ms |
198488 KB |
Output is correct |
20 |
Correct |
43 ms |
199000 KB |
Output is correct |
21 |
Correct |
40 ms |
197212 KB |
Output is correct |
22 |
Correct |
41 ms |
197724 KB |
Output is correct |
23 |
Correct |
43 ms |
198336 KB |
Output is correct |
24 |
Correct |
47 ms |
198996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
506 ms |
265280 KB |
Output is correct |
2 |
Correct |
894 ms |
332712 KB |
Output is correct |
3 |
Correct |
1329 ms |
398932 KB |
Output is correct |
4 |
Correct |
1757 ms |
467624 KB |
Output is correct |
5 |
Correct |
566 ms |
265872 KB |
Output is correct |
6 |
Correct |
1078 ms |
331776 KB |
Output is correct |
7 |
Correct |
1556 ms |
396756 KB |
Output is correct |
8 |
Correct |
2128 ms |
461608 KB |
Output is correct |
9 |
Correct |
536 ms |
265776 KB |
Output is correct |
10 |
Correct |
977 ms |
332228 KB |
Output is correct |
11 |
Correct |
1420 ms |
398092 KB |
Output is correct |
12 |
Correct |
1846 ms |
462948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
196688 KB |
Output is correct |
2 |
Correct |
39 ms |
196584 KB |
Output is correct |
3 |
Correct |
39 ms |
196700 KB |
Output is correct |
4 |
Correct |
38 ms |
196692 KB |
Output is correct |
5 |
Correct |
38 ms |
196692 KB |
Output is correct |
6 |
Correct |
38 ms |
196792 KB |
Output is correct |
7 |
Correct |
38 ms |
196692 KB |
Output is correct |
8 |
Correct |
38 ms |
196956 KB |
Output is correct |
9 |
Correct |
38 ms |
196700 KB |
Output is correct |
10 |
Correct |
38 ms |
196948 KB |
Output is correct |
11 |
Correct |
39 ms |
196696 KB |
Output is correct |
12 |
Correct |
39 ms |
196956 KB |
Output is correct |
13 |
Correct |
40 ms |
197208 KB |
Output is correct |
14 |
Correct |
40 ms |
197980 KB |
Output is correct |
15 |
Correct |
42 ms |
198368 KB |
Output is correct |
16 |
Correct |
43 ms |
198924 KB |
Output is correct |
17 |
Correct |
40 ms |
197392 KB |
Output is correct |
18 |
Correct |
41 ms |
197712 KB |
Output is correct |
19 |
Correct |
42 ms |
198488 KB |
Output is correct |
20 |
Correct |
43 ms |
199000 KB |
Output is correct |
21 |
Correct |
40 ms |
197212 KB |
Output is correct |
22 |
Correct |
41 ms |
197724 KB |
Output is correct |
23 |
Correct |
43 ms |
198336 KB |
Output is correct |
24 |
Correct |
47 ms |
198996 KB |
Output is correct |
25 |
Correct |
506 ms |
265280 KB |
Output is correct |
26 |
Correct |
894 ms |
332712 KB |
Output is correct |
27 |
Correct |
1329 ms |
398932 KB |
Output is correct |
28 |
Correct |
1757 ms |
467624 KB |
Output is correct |
29 |
Correct |
566 ms |
265872 KB |
Output is correct |
30 |
Correct |
1078 ms |
331776 KB |
Output is correct |
31 |
Correct |
1556 ms |
396756 KB |
Output is correct |
32 |
Correct |
2128 ms |
461608 KB |
Output is correct |
33 |
Correct |
536 ms |
265776 KB |
Output is correct |
34 |
Correct |
977 ms |
332228 KB |
Output is correct |
35 |
Correct |
1420 ms |
398092 KB |
Output is correct |
36 |
Correct |
1846 ms |
462948 KB |
Output is correct |
37 |
Correct |
952 ms |
269152 KB |
Output is correct |
38 |
Correct |
1444 ms |
336232 KB |
Output is correct |
39 |
Correct |
1788 ms |
404132 KB |
Output is correct |
40 |
Correct |
2036 ms |
469952 KB |
Output is correct |
41 |
Correct |
1020 ms |
267348 KB |
Output is correct |
42 |
Correct |
1607 ms |
333064 KB |
Output is correct |
43 |
Correct |
1980 ms |
397856 KB |
Output is correct |
44 |
Correct |
2348 ms |
462792 KB |
Output is correct |
45 |
Correct |
1278 ms |
267100 KB |
Output is correct |
46 |
Correct |
1862 ms |
333780 KB |
Output is correct |
47 |
Correct |
2184 ms |
398680 KB |
Output is correct |
48 |
Correct |
2299 ms |
464532 KB |
Output is correct |