Submission #1017211

#TimeUsernameProblemLanguageResultExecution timeMemory
1017211vjudge1Klasika (COCI20_klasika)C++17
0 / 110
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; struct node { node * ch[2]; node() { ch[0] = ch[1] = NULL; } void insert(int x, int b = 31) { if(b == -1) return; bool bit = (1 << b) & x; if(ch[bit] == NULL) ch[bit] = new node(); ch[bit] -> insert(x, b - 1); } int query(int x, int b = 31) { if(b == -1) return 0; bool bit = (1 << b) & x; if(ch[!bit] != NULL) return (1 << b) + ch[!bit] -> query(x, b - 1); return ch[bit] -> query(x, b - 1); } }; const int N = 2'00'000 + 5; node *Tries[N]; int path[N], par[N]; int main() { int q; cin >> q; int cnt = 1; Tries[1] = new node(); for(int i = 0; i < q; i++) { string cmd; int a, b; cin >> cmd >> a >> b; if(cmd == "Query") { cout << Tries[b] -> query(path[a]); } else { cnt++; path[cnt] = path[a] ^ b; if(q > 2000) Tries[1] -> insert(path[cnt]); else { par[cnt] = a; Tries[cnt] = new node(); int cur = cnt; while(cur > 0) { Tries[cur] -> insert(path[cnt]); cur = par[cur]; } } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...