답안 #841575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841575 2023-09-01T17:27:14 Z WLZ XORanges (eJOI19_xoranges) C++17
100 / 100
219 ms 45492 KB
#include <bits/stdc++.h>
using namespace std;

struct node {
  int i, j;
  int val;
  node *left, *right;
};

node *build(int i, int j, const vector<int>& a) {
  if (i == j) {
    return new node{i, j, a[i], nullptr, nullptr};
  } 
  node *left = build(i, (i + j) / 2, a);
  node *right = build((i + j) / 2 + 1, j, a);
  return new node{i, j, (left->val ^ right->val), left, right};
}

int query(node *cur, int i, int j) {
  if (cur->j < i || cur->i > j) {
    return 0;
  }
  if (cur->i >= i && cur->j <= j) {
    return cur->val;
  }
  return query(cur->left, i, j) ^ query(cur->right, i, j);
}

void update(node *cur, int i, int new_val) {
  if (cur->j < i || cur->i > i) {
    return;
  }
  if (cur->i == i && cur->j == i) {
    cur->val = new_val;
    return;
  } 
  update(cur->left, i, new_val);
  update(cur->right, i, new_val);
  cur->val = cur->left->val ^ cur->right->val;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> odd_in(n + 1), even_in(n + 1);
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) {
      cin >> even_in[i];
    } else {
      cin >> odd_in[i];
    }
  }
  node *odd = build(1, n, odd_in);
  node *even = build(1, n, even_in);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i, j;
      cin >> i >> j;
      if (i % 2 == 0) {
        update(even, i, j);
      } else {
        update(odd, i, j);
      }
    } else {
      int l, u;
      cin >> l >> u;
      if ((u - l + 1) % 2 == 0) {
        cout << 0 << '\n';
        continue;
      }
      if (l % 2 == 0) {
        cout << query(even, l, u) << '\n';
      } else {
        cout << query(odd, l, u) << '\n';
      }
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 45416 KB Output is correct
2 Correct 210 ms 45492 KB Output is correct
3 Correct 197 ms 45396 KB Output is correct
4 Correct 116 ms 45248 KB Output is correct
5 Correct 117 ms 45192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 3 ms 1372 KB Output is correct
14 Correct 3 ms 1372 KB Output is correct
15 Correct 207 ms 45416 KB Output is correct
16 Correct 210 ms 45492 KB Output is correct
17 Correct 197 ms 45396 KB Output is correct
18 Correct 116 ms 45248 KB Output is correct
19 Correct 117 ms 45192 KB Output is correct
20 Correct 208 ms 45140 KB Output is correct
21 Correct 215 ms 45384 KB Output is correct
22 Correct 219 ms 45180 KB Output is correct
23 Correct 126 ms 45260 KB Output is correct
24 Correct 139 ms 45296 KB Output is correct