Submission #1134246

#TimeUsernameProblemLanguageResultExecution timeMemory
1134246steveonalexXOR (IZhO12_xor)C++20
100 / 100
115 ms26076 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return __lg(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n"){ for(auto item: container) cout << item << separator; cout << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int INF = 1e9 + 69; struct Trie{ struct Node{ int mi; int child[2]; Node(){mi = INF; memset(child, -1, sizeof child);} }; vector<Node> a; Trie(){ a.push_back(Node()); } void add_child(int &x){ x = a.size(); a.push_back(Node()); } void add(int x, int i){ int id= 0; minimize(a[id].mi, i); for(int j = 29; j >= 0; --j) { int digit = GETBIT(x, j); if (a[id].child[digit] == -1) add_child(a[id].child[digit]); id = a[id].child[digit]; minimize(a[id].mi, i); } } int get_mi_xor(int x, int y){ int id = 0; int ans = INF; bool escaped_early = false; for(int j = 29;j >= 0; --j){ int digit = GETBIT(x, j); if (GETBIT(y, j)){ int v = a[id].child[digit ^ 1]; if (v == -1) { escaped_early = true; break; } id = v; } else{ int u = a[id].child[digit], v = a[id].child[digit ^ 1]; if (v != -1){ minimize(ans, a[v].mi); } if (u == -1) { escaped_early = true; break; } id = u; } } if (!escaped_early) minimize(ans, a[id].mi); return ans; } }; void solve(){ int n, x; cin >> n >> x; vector<int> a(n+1); for(int i = 1; i <= n; ++i){ cin >> a[i]; a[i] ^= a[i-1]; } Trie tri; int ans = 0, pos = 0; for(int i = 0; i <= n; ++i){ tri.add(a[i], i); if (maximize(ans, i - tri.get_mi_xor(a[i], x))){ pos = i - ans + 1; } } cout << pos << " " << ans << "\n"; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t start = clock(); solve(); cerr << "Time elapsed: " << clock() - start << "ms!\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...