Submission #1021003

#TimeUsernameProblemLanguageResultExecution timeMemory
1021003MinbaevXOR (IZhO12_xor)C++17
100 / 100
142 ms26080 KiB
#include<bits/stdc++.h> using namespace std; int par[250005],tree[250005*30][2],node,sub[250005*30],n,k; void upd(int x){ int now=0; for(int i=29;i>=0;i--){ int bit=par[x]>>i&1; if(!tree[now][bit]) tree[now][bit]=++node; now=tree[now][bit]; sub[now]=max(sub[now],x); } } int get(int x){ int now=0,val=0,res=0; for(int i=29;i>=0;i--){ int bit=x>>i&1; int v1=tree[now][bit^1]; int v0=tree[now][bit]; if(v0&&v1){ if(val+(1<<i)>=k) res=max(res,sub[v1]),now=v0; else val+=(1<<i),now=v1; } else if(v1){ if(val+(1<<i)>=k) res=max(res,sub[v1]); val+=(1<<i); now=v1; } else now=v0; } return res; } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++){ scanf("%d",&par[i]); par[i]^=par[i-1]; } int ans,mx=0; for(int i=n;i>=1;i--){ upd(i); int res=get(par[i-1]); if(res&&res-i+1>=mx)mx=res-i+1,ans=i; } printf("%d %d",ans,mx); }

Compilation message (stderr)

xor.cpp: In function 'int get(int)':
xor.cpp:27:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |    if(val+(1<<i)>=k)
      |    ^~
xor.cpp:29:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   29 |     val+=(1<<i);
      |     ^~~
xor.cpp: In function 'int main()':
xor.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~
xor.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d",&par[i]);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...