Submission #883487

#TimeUsernameProblemLanguageResultExecution timeMemory
883487NintsiChkhaidzeXOR (IZhO12_xor)C++17
100 / 100
144 ms39452 KiB
#include <bits/stdc++.h> #define pb push_back #define s second #define f first #define left (h<<1),l,(l + r)/2 #define right ((h<<1)|1),(l + r)/2 + 1,r #define pii pair<int,int> #define ll long long // #define int ll using namespace std; const int N = 250000 + 5; int a[N],p[N],tot = 1,child[N * 33][4],val[N * 33]; void upd(int k,int i){ int cur = 1; for (int j = 30; j >= 0; j--){ int b = (k & (1<<j)) > 0; if (!child[cur][b]){ child[cur][b] = ++tot; } cur = child[cur][b]; val[cur] = max(val[cur],i); } } int find(int i,int mask,int lim){ // ... == mask ^ p[i - 1] mask ^= p[i - 1]; int cur = 1; for (int j = 30; j >= lim; j--){ int b = (mask & (1<<j)) > 0; if (!child[cur][b]) return -1; cur = child[cur][b]; } return val[cur] - i + 1; } signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); // freopen("game.in", "r", stdin); // freopen("game.out", "w", stdout); int n,x; cin>>n>>x; for (int i = 1; i <= n; i++){ cin >> a[i]; p[i] = p[i - 1] ^ a[i]; } int ans1 = 0,ans2 = 0; for (int i = n; i >= 1; i--){ upd(p[i],i); int res = find(i,x,0); if (res >= ans2) ans1 = i,ans2 = res; int mask = 0; for (int j = 30; j >= 0; j--){ if (!(x & (1<<j))){ int res = find(i,(mask ^ (1<<j)),j); if (res >= ans2) ans1=i,ans2=res; } mask ^= (x & (1<<j)); } } cout<<ans1<<" "<<ans2; }
#Verdict Execution timeMemoryGrader output
Fetching results...