Submission #1172212

#TimeUsernameProblemLanguageResultExecution timeMemory
1172212shahodXOR (IZhO12_xor)C++20
100 / 100
148 ms35208 KiB
#include <bits/stdc++.h> using namespace std; struct node { int nxt[2]{}, sz = 0, mn = 1e9; int &operator[](int x) { return nxt[x]; } }; struct trie { const int bits = 31; vector<node> t; int new_node() { t.push_back(node()); return t.size() - 1; } trie() { t.clear(); new_node(); } int sz(int u) { return t[u].sz; } void update(int x, int op, int j) { int u = 0; for (int bit = bits - 1; bit >= 0; bit--) { int b = x >> bit & 1; if (!t[u][b]) { t[u][b] = new_node(); } u = t[u][b]; t[u].sz += op; t[u].mn = min(t[u].mn, j); } } pair<long long, int> query(long long x) { long long u = 0, ret = 0; for (int bit = bits - 1; bit >= 0; bit--) { int b = x >> bit & 1; if (sz(t[u][b ^ 1])) { ret |= (1LL << bit); u = t[u][b ^ 1]; } else { u = t[u][b]; } } return make_pair(ret, t[u].mn); } } trie; void gojo() { long long n, x; cin >> n >> x; vector<long long> pre(n + 1); for (int i = 1; i <= n; i++) { int a; cin >> a; pre[i] = pre[i - 1] ^ a; } int idx = n, len = 0; for (int i = 1; i <= n; i++) { auto it = trie.query(pre[i]); if (it.first >= x) { if ((i - it.second > len) || ((i - it.second == len) && it.first + 1 < idx)) { idx = it.second + 1; len = i - it.second; } } trie.update(pre[i], 1, i); } cout << idx << ' ' << len; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { gojo(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...