제출 #1178773

#제출 시각아이디문제언어결과실행 시간메모리
1178773qrnXOR (IZhO12_xor)C++20
0 / 100
2 ms3392 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define fi first #define se second // #define endl "\n" #define ALL(x) x.begin(), x.end() #define sz(x) x.size() #define intt long long const intt mod = 1e9 + 7; const intt inf = 1e18; const intt mxN = 2e5 + 5; vector<intt> A(mxN), pref(mxN); struct trie { trie* left; trie *right; set<intt> idx; intt data; trie () { left = nullptr; right = nullptr; idx.clear(); data = -1; } }; void add(trie *& root, intt X, intt idxi) { trie *node = root; for(intt bit = 30; bit >= 0; bit--) { node->data = ((1 << bit) & X); if((1 << bit) & X) { if(node->right == nullptr) { node->right = new trie(); } node->idx.insert(idxi); node = node->right; } else { if(node->left == nullptr) { node->left = new trie(); } node->idx.insert(idxi); node = node->left; } } } intt get(trie *& root, intt X, intt num) { intt ret = inf, ret2 = 0; trie *node = root; for(intt i = 30; i >= 0; i--) { intt numbit = ((1 << i) & X) > 0; intt Xbit = ((1 << i) & X) > 0; // cout << num << " " << i << endl; if(Xbit) { if(numbit == 0 && node->right == nullptr) return ret; if(numbit == 0) node = node->right; else node = node = node->left; // if(i == 2) cout << "ASDSAD" << endl; } else { if(numbit == 0 && node->right != nullptr) { ret = min(ret, *node->right->idx.begin()); node = node->left; } else if(numbit == 1 && node->left != nullptr) { ret = min(ret, *node->left->idx.begin()); node = node->right; } } // cout << "ASD"<< endl; if(node->idx.size() > 0) { // cout << "OHA: "; // for(auto u : node->idx) cout << u << ":ASDASd"<< endl; ret2 = *node->idx.begin(); } } return min(ret, ret2); } void solve() { intt N, x; cin >> N >> x; A.resize(N); for(auto &a : A) cin >> a; trie *root = new trie(); pref.resize(N); for(intt i = 0; i < N; i++) { pref[i] = A[i]; if(i) pref[i] ^= pref[i-1]; } // for(intt i : pref) cout << i << " "; // cout << endl; intt diff = 0, l = 0, r = 0; add(root, pref[0], 0); for(intt i = 1; i < N; i++) { intt for_l = get(root, x, pref[i]); // cout << i << ": " << for_l << endl; if(for_l == -1) continue; if(i - for_l > diff) { r = i + 1; l = for_l + 1; diff = i - for_l; } add(root, pref[i], i); } l++; cout << l << " " << r-l+1 << endl; } signed main() { SPEED; intt tst = 1; // cin >> tst; while (tst--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...