Cod sursa(job #3355332)

Utilizator wizardragonWizard Dragon wizardragon Data 22 mai 2026 15:50:55
Problema Secventa 3 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>
using namespace std;
struct node{
  node* k[2];
  node() {
    k[0]=k[1]=0;
  }
};
void add(node* c,int x) {
  for(int i=20;i>=0;i--) {
    int b=!!(x&(1<<i));
    if(!c->k[b]){
      c->k[b]=new node;
    }
    c=c->k[b];
  }
}
int fndbest(node*c, int x){
  int sol=0;
  for(int i=20;i>=0;i--) {
    int b=!!(x&(1<<i));
    if(c->k[1^b]){
      sol+=(1<<i);
      c=c->k[1^b];
    }else{
      assert(c->k[b]);
      c=c->k[b];
    }
  }
  return sol;
}
int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  freopen("xormax.in","r",stdin);freopen("xormax.out","w",stdout);
  int n;
  cin>>n;
  vector<int> s(n+1,0);
  for(int i=1;i<=n;i++) {
    int x;
    cin>>x;
    s[i]=s[i-1]^x;
  }
  node* root=new node;
  vector<int> sols(n+1,0);
  for(int i=0;i<=n;i++){
    add(root,s[i]);
    sols[i]=fndbest(root,s[i]);
  }
  int mx=*max_element(sols.begin(),sols.end()),i=0;
  while(sols[i]!=mx){
    i++;
  }
  int j=i-1;
  while((s[i]^s[j])!=sols[i]){
    j--;
    assert(j>=0);
  }
  assert(s[i]^s[j]==sols[i]);
  cout<<mx<<" "<<j+1<<" "<<i<<"\n";
  return 0;
}