#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, LOG_A = 31;
const int LOGN = 20;
int k;
int basis[LOG_A];
int num[N], d[N];
int p[N][LOGN];
int sz;
int ct = 1;
void insertVector(int mask) {
for (int i = 0; i < LOG_A; i++) {
if ((mask & (1<<i)) == 0) continue;
if (!basis[i]) {
basis[i] = mask;
++sz;
return;
}
mask ^= basis[i];
}
}
int maxxor(int cur){
for (int i = LOG_A; i >= 0; i--){
if ((cur & (1<<i)) == 0){
if (basis[i]){
cur ^= basis[i];
return cur;
}
}
}
}
int is_parent(int u, int v){
int dif = d[u] - d[v];
if (dif < 0) return 0;
while (dif){
int lsb = 31-__builtin_clz(dif);
u = p[u][lsb];
dif -= (1<<lsb);
}
return (u==v);
}
int main() {
int q;
cin >> q;
while (q--) {
string Q;
int a,b;
cin >> Q >> a >> b;
if (Q == "Add"){
num[++ct] = num[a]^b;
//printf("added %d %d\n",ct,num[ct]);
p[ct][0] = a;
d[ct] = d[a]+1;
for (int k = 1; k < LOGN; k++){
if (p[ct][k-1] == -1) break;
p[ct][k] = p[p[ct][k-1]][k-1];
}
insertVector(num[ct]);
}
else if (Q == "Query"){
int temp = maxxor(num[a]);
//printf("%d %d\n",a,temp);
if (q <= 2000){
int ans = 0;
for (int i = 1; i <= ct; i++){
if (is_parent(i,b)){
ans = max(ans,num[i]^num[a]);
}
}
//if (b == 1) assert(temp == ans);
printf("%d\n",ans);
}
else printf("%d\n",temp);
}
}
return 0;
}
Compilation message
klasika.cpp: In function 'int maxxor(int)':
klasika.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
13 ms |
384 KB |
Output is correct |
14 |
Correct |
13 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
384 KB |
Output is correct |
16 |
Correct |
12 ms |
488 KB |
Output is correct |
17 |
Correct |
12 ms |
384 KB |
Output is correct |
18 |
Correct |
15 ms |
384 KB |
Output is correct |
19 |
Correct |
12 ms |
384 KB |
Output is correct |
20 |
Correct |
11 ms |
512 KB |
Output is correct |
21 |
Correct |
17 ms |
384 KB |
Output is correct |
22 |
Correct |
16 ms |
512 KB |
Output is correct |
23 |
Correct |
14 ms |
512 KB |
Output is correct |
24 |
Correct |
13 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2533 ms |
5548 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
13 ms |
384 KB |
Output is correct |
14 |
Correct |
13 ms |
384 KB |
Output is correct |
15 |
Correct |
13 ms |
384 KB |
Output is correct |
16 |
Correct |
12 ms |
488 KB |
Output is correct |
17 |
Correct |
12 ms |
384 KB |
Output is correct |
18 |
Correct |
15 ms |
384 KB |
Output is correct |
19 |
Correct |
12 ms |
384 KB |
Output is correct |
20 |
Correct |
11 ms |
512 KB |
Output is correct |
21 |
Correct |
17 ms |
384 KB |
Output is correct |
22 |
Correct |
16 ms |
512 KB |
Output is correct |
23 |
Correct |
14 ms |
512 KB |
Output is correct |
24 |
Correct |
13 ms |
512 KB |
Output is correct |
25 |
Incorrect |
2533 ms |
5548 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |