Submission #1103729

#TimeUsernameProblemLanguageResultExecution timeMemory
1103729FubuGoldKlasika (COCI20_klasika)C++14
0 / 110
452 ms120196 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; const int LG = __lg(MAXN); struct Trie { struct Node { Node *ch[2]; set<int> id; Node() { ch[0] = ch[1] = nullptr; } }; Node *head = new Node(); void add(int x,int id) { Node *cur = head; for (int i=30;i>=0;i--) { int c = (x >> i) & 1; if (cur->ch[c] == nullptr) cur->ch[c] = new Node(); cur = cur->ch[c]; cur->id.insert(id); } } int query(int l,int r,int x) { Node *cur = head; int ans = 0; // cerr << l << ' ' << r << ' ' << x << '\n'; for (int i=30;i>=0;i--) { int c = (x >> i) & 1; if (cur->ch[c ^ 1] == nullptr) { if (cur->ch[c] == nullptr) return ans; cur = cur->ch[c]; } else { auto tmp = cur->ch[c^1]->id.lower_bound(l); if (tmp == cur->ch[c^1]->id.end() || (*tmp) > r) { if (cur->ch[c] == nullptr) return ans; cur = cur->ch[c]; } else { // cerr << i << ' ' << *tmp << '\n'; ans ^= 1 << i; cur = cur->ch[c ^ 1]; } } } return ans; } } trie; struct Query { int type; int x,y; Query(){}; } query[MAXN+1]; vector<int> adj[MAXN+1]; int xor_p[MAXN+1]; int tin[MAXN+1],tout[MAXN+1]; int timeDFS = 0; void dfs(int u) { tin[u] = ++timeDFS; for (int i=0;i<adj[u].size();i++) { int v = adj[u][i]; dfs(v); } tout[u] = timeDFS; } int main() { cin.tie(0) -> sync_with_stdio(0); int q; cin >> q; int cnt = 1; for (int i=1;i<=q;i++) { string s; cin >> s >> query[i].x >> query[i].y; if (s == "Add") { cnt++; adj[query[i].x].push_back(cnt); xor_p[cnt] = xor_p[query[i].x] ^ query[i].y; } else { query[i].type = 1; } } dfs(1); cnt = 1; for (int i=1;i<=q;i++) { if (query[i].type == 0) { cnt++; trie.add(xor_p[cnt],tin[cnt]); } else { // cerr << query[i].y << ' ' << tin[query[i].y] << ' ' << tout[query[i].y] << '\n'; cout << trie.query(tin[query[i].y],tout[query[i].y],xor_p[query[i].x]) << '\n'; } } return 0; }

Compilation message (stderr)

klasika.cpp: In function 'void dfs(int)':
klasika.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i=0;i<adj[u].size();i++) {
      |                  ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...