제출 #255463

#제출 시각아이디문제언어결과실행 시간메모리
255463lani1akeaXORanges (eJOI19_xoranges)C++17
100 / 100
165 ms11460 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'

using namespace std;

const int MOD = 1e9 + 7;
const int N = 2 * 1e5 + 10;

int n, q, a[N], t1[4*N], t2[4*N];

void build(int x, int l, int r) {
  if (l == r) {
    if (l % 2) t1[x] = a[l];
    else t2[x] = a[l];
    return;
  }
  int m = (l + r) / 2;
  build(x*2, l, m);
  build(x*2+1, m+1, r);
  t1[x] = t1[x*2] ^ t1[x*2+1];
  t2[x] = t2[x*2] ^ t2[x*2+1];
}

void update(int x, int l, int r, int i, int v) {
  if (l == r) {
    if (i % 2) t1[x] = v;
    else t2[x] = v;
    return;
  }
  int m = (l + r) / 2;
  if (i > m) update(2*x+1, m+1, r, i, v);
  else update(2*x, l, m, i, v);
  t1[x] = t1[2*x] ^ t1[2*x+1];
  t2[x] = t2[2*x] ^ t2[2*x+1];
}

int get(int x, int lx, int rx, int l, int r, int type) {
  if (lx > r or rx < l) return 0;
  if (lx >= l and rx <= r) {
    if (type & 1) return t1[x];
    else return t2[x];
  }
  int m = (lx + rx) / 2;
  return get(2*x, lx, m, l, r, type) ^ get(2*x+1, m+1, rx, l, r, type);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  build(1, 0, n - 1);

  while(q--) {
    int t, i, j;
    cin >> t >> i >> j;
    if (t&1) {
      update(1, 0, n-1, i-1, j);
    } else {
      if (i % 2 != j % 2)
        cout << "0\n";
      else
        cout << get(1, 0, n-1, i-1, j-1, (i-1)%2) << endl;
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...