제출 #261580

#제출 시각아이디문제언어결과실행 시간메모리
261580sckmdXOR (IZhO12_xor)C++14
0 / 100
1 ms512 KiB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 500005
int a[MAXN];

struct node
{
  node* nula;
  node* kec;
  int minpos=9999999;
  //bool leaf;
};
node* root;

void update(int br,int pos)
{
  node* now = root;
  for(int i = 31; i >= 0; i--)
  {
    //if(now->minpos == NULL)now->minpos = 999999999;
    now->minpos = min(now->minpos,pos);
    if(br&(1<<i))
    {
      if(now->kec == NULL)now->kec = new node();
      now = now->kec;
    }
    else
    {
      if(now->nula == NULL)now->nula = new node();
      now = now->nula;
    }
  }
  //if(now->minpos == NULL)now->minpos = 999999999;
  now->minpos = min(now->minpos,pos);
}
int query(int br,int x)
{
  //br je trazeni
  //x je mojbroj
  node* now = root;
  int res = 9999999;
  for(int i = 31; i >= 0; i--)
  {
    if(br & (1<<i))
    {
      if(x & (1<<i))
      {
        now = now->nula;
      }
      else
      {
        now = now->kec;
      }
    }
    else
    {
      if(x & (1<<i))
      {
        res = min(res,now->nula->minpos);
        now = now->kec;
      }
      else
      {
        res = min(res,now->kec->minpos);
        now = now->nula;
      }
    }
  }
  res = min(res,now->minpos);
  return res;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int n,x;
  cin >> n >> x;
  root = new node();
  update(0,1);
  for(int i = 1; i <= n; i++)
  {
    cin >> a[i];
    a[i]^=a[i-1];
  }
  int ans = 0;
  for(int i = 1; i <= n; i++)
  {
    ans = max(ans,i-query(x,a[i])+1);
    update(a[i],i);
  }
  cout << ans;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...