Submission #1062121

#TimeUsernameProblemLanguageResultExecution timeMemory
1062121VMaksimoski008XOR (IZhO12_xor)C++17
0 / 100
461 ms262144 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; struct Node { map<int, Node*> mp; Node() {} }; struct Trie { Node *root; Trie() { root = new Node(); } ~Trie() { delete root; } void insert(int x) { Node *curr = root; for(int i=30; i>=0; i--) { bool b = x & (1 << i); if(!curr->mp.count(b)) curr->mp[b] = new Node(); curr = curr->mp[b]; } } int XOR(int x) { int ans = 0; Node *curr = root; for(int i=30; i>=0; i--) { bool b = x & (1 << i); if(curr->mp.count(!b)) { ans |= (1 << i); curr = curr->mp[!b]; } else { curr = curr->mp[b]; } } return ans; } }; signed main() { int n, m; cin >> n >> m; vector<int> v(n+1); for(int i=1; i<=n; i++) cin >> v[i]; vector<int> pref(n+1); for(int i=1; i<=n; i++) pref[i] = v[i] ^ pref[i-1]; int l=1, r=n, ans=1; while(l <= r) { int mid = (l + r) / 2; bool ok = 0; Trie trie; for(int i=mid; i<=n&&!ok; i++) { trie.insert(pref[i-mid]); if(trie.XOR(pref[i]) >= m) ok = 1; } if(ok) l = mid + 1, ans = mid; else r = mid - 1; } for(int i=ans; i<=n; i++) { if((pref[i] ^ pref[i-ans]) >= m) { cout << i-ans+1 << " " << ans << '\n'; return 0; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...