Submission #1074781

#TimeUsernameProblemLanguageResultExecution timeMemory
1074781nima_aryanXOR (IZhO12_xor)C++17
100 / 100
106 ms91940 KiB
#include <bits/stdc++.h>

using namespace std;

constexpr int N = 7600000;
vector<array<int, 2>> trie(N);
vector<int> tag(N);
int tot = 1;

void insert(int x, int i) {
  int p = 1;
  for (int t = 30; t >= 0; --t) {
    int& q = trie[p][x >> t & 1];
    if (!q) {
      q = ++tot;
    }
    p = q;
    if (!tag[p]) {
      tag[p] = i;
    }
  }
}
int get(int x, int v) {
  int res = -1;
  int p = 1;
  for (int t = 30; t >= 0; --t) {
    int bx = x >> t & 1;
    int bv = v >> t & 1;
    if (bv) {
      p = trie[p][bx ^ 1];
    } else {
      res = max(res, tag[trie[p][bx ^ 1]]);
      p = trie[p][bx];
    }
    if (!p) {
      return res;
    }
  }
  res = max(res, tag[p]);
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, x;
  cin >> n >> x;

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  int bk = 0, bi = 0;
  insert(0, n);
  for (int i = n - 1, s = 0; i >= 0; --i) {
    s ^= a[i];
    int j = get(s, x);
    if (j - i >= bk) {
      bk = j - i;
      bi = i;
    }
    insert(s, i);
  }
  cout << bi + 1 << " " << bk << "\n";

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...