Submission #487908

#TimeUsernameProblemLanguageResultExecution timeMemory
487908hoanghq2004Klasika (COCI20_klasika)C++14
110 / 110
2474 ms466948 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; const int Nmax = 2e5 + 10; int sz; struct node { int to[2]; set <int> s; }; vector <node> trie; void add(int x, int ti) { int u = 0; for (int i = 29; i >= 0; --i) { if (!trie[u].to[x >> i & 1]) { trie.push_back(node()); trie[u].to[x >> i & 1] = trie.size() - 1; } u = trie[u].to[x >> i & 1]; trie[u].s.insert(ti); } } int get(int x, int L, int R) { int u = 0; int ans = 0; for (int i = 29; i >= 0; --i) { auto iter = trie[trie[u].to[x >> i & 1 ^ 1]].s.lower_bound(L); if (iter == trie[trie[u].to[x >> i & 1 ^ 1]].s.end() || *iter > R) u = trie[u].to[x >> i & 1]; else ans += (1 << i), u = trie[u].to[x >> i & 1 ^ 1]; } return ans; } int q; vector <pair <int, int> > e[Nmax]; int in[Nmax], out[Nmax], ti, d[Nmax]; void dfs(int u) { in[u] = ++ti; for (auto [v, w]: e[u]) { d[v] = d[u] ^ w; dfs(v); } out[u] = ti; } vector <tuple <string, int, int> > queries; int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); trie.push_back(node()); cin >> q; int n = 1; while (q--) { string s; int x, y; cin >> s >> x >> y; if (s == "Add") ++n, e[x].push_back({n, y}), queries.push_back({s, n, y}); else queries.push_back({s, x, y}); } dfs(1); add(d[1], in[1]); for (auto [s, x, y]: queries) { if (s == "Add") add(d[x], in[x]); else cout << get(d[x], in[y], out[y]) << '\n'; } }

Compilation message (stderr)

klasika.cpp: In function 'int get(int, int, int)':
klasika.cpp:33:44: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   33 |         auto iter = trie[trie[u].to[x >> i & 1 ^ 1]].s.lower_bound(L);
      |                                     ~~~~~~~^~~
klasika.cpp:34:44: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   34 |         if (iter == trie[trie[u].to[x >> i & 1 ^ 1]].s.end() || *iter > R) u = trie[u].to[x >> i & 1];
      |                                     ~~~~~~~^~~
klasika.cpp:35:53: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   35 |         else ans += (1 << i), u = trie[u].to[x >> i & 1 ^ 1];
      |                                              ~~~~~~~^~~
klasika.cpp: In function 'void dfs(int)':
klasika.cpp:46:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for (auto [v, w]: e[u]) {
      |               ^
klasika.cpp: In function 'int main()':
klasika.cpp:69:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     for (auto [s, x, y]: queries) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...