Cod sursa(job #3332138)

Utilizator GliggyGligor Andrei Gliggy Data 4 ianuarie 2026 16:38:51
Problema Xor Max Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.39 kb
// Copilot Rules:
// RULE: There shouldnt be any spaces in the code, except after commas.
// RULE: All variables in main should be declared globally, and can be used before they are defined.
// RULE: All open curly braces should be placed on the same line as the function or control structure they belong to, not on the line after.
#include <bits/stdc++.h>

using namespace std;
ifstream fin("xormax.in");   //strudel
ofstream fout("xormax.out"); //xormax
int n,i,x,pre,j,max1,v,st,dr,st1;
bool b[25];
struct nod{
    nod *kid[2]={nullptr};
    int ind=0;
};
nod r;
void transf(int x){
    int i=0;
    for(;x>0;x/=2,i++) b[i]=x%2;
    for(;i<=25;i++) b[i]=0;
}
int getmax(){
    int rez=0;
    nod *curr=&r;
    for(int i=25;i>=0;i--){
        if(curr->kid[1-b[i]]) curr=curr->kid[1-b[i]], rez=rez*2+1;
        else curr=curr->kid[b[i]], rez=rez*2;
    }
    st1=curr->ind+1;
    return rez;
}
void push(){
    nod *curr=&r;
    for(int i=25;i>=0;i--){
        if(curr->kid[b[i]]) curr=curr->kid[b[i]];
        else curr->kid[b[i]]=new nod, curr=curr->kid[b[i]];
    }
    curr->ind=i;
}
int main()
{
    fin>>n;
    push();
    for(i=1;i<=n;i++){
        fin>>x;
        pre=pre^x;
        transf(pre);
        v=getmax();
        if(v>max1) max1=v,dr=i,st=st1;
        if(x>max1) max1=x,dr=i,st=i;
        push();
    }
    fout<<max1<<' '<<st<<" "<<dr;
    return 0;
}