제출 #90377

#제출 시각아이디문제언어결과실행 시간메모리
90377popovicirobertXOR (IZhO12_xor)C++14
0 / 100
293 ms263168 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; struct Trie { Trie *son[2]; int pos; Trie() { son[0] = son[1] = NULL; pos = 0; } }; Trie *root = new Trie; void ins(Trie *nod, int bit, int val, int pos) { if(bit == -1) { nod -> pos = pos; } else { int b = ((val & (1 << bit)) > 0); if(nod -> son[b] == NULL) { nod -> son[b] = new Trie; } ins(nod -> son[b], bit - 1, val, pos); nod -> pos = max(nod -> pos, pos); } } int query(Trie *nod, int bit, int val, int x) { if(nod == NULL) { return -1; } if(bit == -1) { return nod -> pos; } else { if(x & (1 << bit)) { if(val & (1 << bit)) { return query(nod -> son[0], bit - 1, val, x); } else { return query(nod -> son[1], bit - 1, val, x); } } else { int ans = -1; if(val & (1 << bit)) { if(nod -> son[1] != NULL) { ans = nod -> son[1] -> pos; } ans = max(ans, query(nod -> son[0], bit - 1, val, x)); } else { if(nod -> son[0] != NULL) { ans = nod -> son[0] -> pos; } ans = max(ans, query(nod -> son[1], bit - 1, val, x)); } return ans; } } } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n, x; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> x; ins(root, 0, 30, 0); pair <int, int> ans = {0, 0}; int sum = 0; for(i = 1; i <= n; i++) { int val; cin >> val; sum ^= val; int cur = query(root, 30, sum, x); if(cur > ans.first) { ans = {cur, i - cur + 1}; } ins(root, val, 30, i); } cout << ans.second << " " << ans.first; //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...