Submission #854516

#TimeUsernameProblemLanguageResultExecution timeMemory
854516OAleksaXOR (IZhO12_xor)C++14
100 / 100
112 ms91376 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; #define int long long const int maxn = 250069; int trie[30 * maxn][2], n, a[maxn], id, y; int c[30 * maxn]; void add(int x, int p) { int node = 0; for (int i = 29;i >= 0;i--) { int k = ((x & (1 << i)) > 0); if (trie[node][k] == 0) trie[node][k] = ++id; node = trie[node][k]; c[node] = min(c[node], p); } } int search(int x) { int res = n + 1, node = 0; for (int i = 29;i >= 0;i--) { int k = ((x & (1 << i)) > 0); if (y & (1 << i)) { int dr; if (k > 0) dr = 0; else dr = 1; if (!trie[node][dr]) break; node = trie[node][dr]; } else { int dr; if (k > 0) dr = 0; else dr = 1; if (trie[node][dr]) res = min(res, c[trie[node][dr]]); node = trie[node][dr ^ 1]; } } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while(tt--) { cin >> n >> y; --y; // treba mi strknto veci od y sad for (int i = 1;i <= n;i++) cin >> a[i]; for (int i = 1;i < 30 * maxn;i++) c[i] = n + 1; add(0, 0); int ind = 0, k = 0, xr = 0; for (int i = 1;i <= n;i++) { xr ^= a[i]; add(xr, i); int rez = search(xr); if (i - rez > k) { k = i - rez; ind = rez; } else if (rez == k) ind = min(ind, rez); } cout << ind + 1 << " " << k; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...