Submission #1266189

#TimeUsernameProblemLanguageResultExecution timeMemory
1266189rayan_bdXOR (IZhO12_xor)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 550005; #define int long long int a[mxN]; struct Node{ Node* children[2]; int mn_idx; Node(){ children[0] = children[1] = NULL; mn_idx = mxN; } }; struct Trie{ Node* root = new Node(); void add(int val, int idx){ Node* curr = root; for(int i = 32; i >= 0; --i){ int curr_bit = (val & (1 << i)) > 0; if(curr -> children[curr_bit] == NULL) curr -> children[curr_bit] = new Node(); curr = curr -> children[curr_bit]; curr -> mn_idx = min(curr -> mn_idx, idx); } } int query(int val, int idx){ Node* curr = root; int ans = 0; for(int i = 32; i >= 0; --i){ int curr_bit = (val & (1 << i)) > 0; if(curr -> children[1 - curr_bit] && curr -> children[1 - curr_bit] -> mn_idx <= idx){ ans |= 1 << i; curr = curr -> children[1 - curr_bit]; }else{ if(curr -> children[curr_bit] -> mn_idx > idx) break; curr = curr -> children[curr_bit]; } } return ans; } } tr; signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); int n, x, pref = 0; cin >> n >> x; pair<int, int> ans = {0, 0}; for(int i = 1; i <= n; ++i){ cin >> a[i]; tr.add(pref, i); pref ^= a[i]; int st = 1, en = i, best = -1; while(st <= en){ int mid = st + (en - st) / 2; if(tr.query(pref, mid) >= x){ best = i - mid + 1; en = mid - 1; }else{ st = mid + 1; } } if(best != -1){ if(ans.first == best) ans = min(ans, {best, -(best - i - 1)}); else ans = max(ans, {best, -(best - i - 1)}); } } cout << ans.second << " " << ans.first << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...