Submission #523524

#TimeUsernameProblemLanguageResultExecution timeMemory
523524lukameladzeXOR (IZhO12_xor)C++14
0 / 100
2015 ms172084 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back #define int long long using namespace std; const int N = 3e5 + 5; int n,x,a[N],pref,idx,sf[N],posri,le,mx,sz,idd,val; map <int, int> fix[31]; void go(int lee , int rii ){ sz = rii - lee + 1; if (sz >= mx) { le = lee; mx = sz; } } main() { cin>>n>>x; for (int i = 1; i <= n; i++) { cin>>a[i]; } for (int i = 30; i >= 0; i--) { if ((1LL<<i)&x) { idx = i; break; } pref += (1<<i); } for (int j = idx; j >= 0; j--) { fix[j][0] = n + 1; } for(int i = n; i >= 1; i--) { // if (i == 1) cout<<le<<" "<<mx<<endl; sf[i] = sf[i + 1] ^ a[i]; //if (i == 2) cout<<sf[i]<<" "<<(int)(pref&sf[i])<<endl; if ((pref&sf[i])) { le = i; mx = n - i + 1; if (!idd) idd = i; int val = 0; for (int j = idx; j >= 0; j--) { if ((1LL<<j)&sf[i]) val += (1LL<<j); fix[j][val] = max(fix[j][val],i); } continue; } posri = idd - 1; sz = posri - i + 1; if (sz >= mx) { le = i; mx = sz; } int haveto = 0; for (int j = idx; j >= 0; j--) { if ((1<<j)&x) { if (!((1LL<<j)&sf[i])) haveto += (1LL<<j); continue; } if ((1<<j)&sf[i]) { if (fix[j][haveto]) go(i, fix[j][haveto] - 1); haveto += (1LL<<j); continue; } if (fix[j][haveto + (1LL<<j)]) go(i, fix[j][haveto + (1LL<<j)] - 1); } if (fix[0][haveto]) { go(i,fix[0][haveto] - 1); } int val = 0; for (int j = idx; j >= 0; j--) { if ((1LL<<j)&sf[i]) val += (1LL<<j); fix[j][val] = max(fix[j][val],i); } } cout<<le<<" "<<mx<<endl; }

Compilation message (stderr)

xor.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...