Submission #676394

# Submission time Handle Problem Language Result Execution time Memory
676394 2022-12-30T16:07:37 Z Truitadepatates XORanges (eJOI19_xoranges) C++14
100 / 100
139 ms 10364 KB
#include <bits/stdc++.h>
using namespace std;

void build(vector<int>& a, vector<int>& segtree, int x, int l, int r){
  if (l == r){
    segtree[x] = a[l];
    return;
  }
  int m = (l+r)/2;
  build(a, segtree, 2*x, l, m);
  build(a, segtree, 2*x+1, m+1, r);
  segtree[x] = segtree[2*x]^segtree[2*x+1];
}

void update(vector<int>&a, vector<int>& segtree, int x, int l, int r, int i, int v){
  if (i < l or i > r) return;
  else if (l == r){
    segtree[x] = v;
    a[l] = v;
  }
  else{
    int m = (l+r)/2;
    if (i <= m) update(a, segtree, 2*x, l, m, i, v);
    else update(a, segtree, 2*x+1, m+1, r, i, v);
    segtree[x] = segtree[2*x]^segtree[2*x+1];
  }
}

int range(vector<int>& segtree, int x, int l, int r, int lx, int rx){
  if (l >= lx && r <= rx) return segtree[x];
  else if (l > rx or r < lx) return 0;
  else{
    int m = (l+r)/2;
    int xor1 = range(segtree, 2*x, l, m, lx, rx);
    int xor2 = range(segtree, 2*x+1, m+1, r, lx, rx);
    return xor1^xor2;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  int n1, n2;
  if (n%2 == 0){
    n1 = n/2;
    n2 = n1;
  }
  else{
    n1 = n/2 + 1;
    n2 = n/2;
  }
  vector<int> aEven(n1);
  vector<int> aOdd(n2);
  vector<int> SegtreeEven(4*n1, 0);
  vector<int> SegtreeOdd(4*n2, 0);
  for (int i = 0; i < n; i++){
    if (i%2 == 0) cin >> aEven[i/2];
    else cin >> aOdd[i/2];
  }
  build(aEven, SegtreeEven, 1, 0, n1-1);
  if (n2 >= 1){
    build(aOdd, SegtreeOdd, 1, 0, n2-1);
  }
  int op, i, v;
  while (q--){
    cin >> op >> i >> v;
    if (op == 1){
      if ((i-1)%2 == 0) update(aEven, SegtreeEven, 1, 0, n1-1, (i-1)/2, v);
      else update(aOdd, SegtreeOdd, 1, 0, n2-1, (i-1)/2, v);
    }
    else{
      int Range = v-i+1;
      if (Range%2 == 0) cout << 0 << "\n";
      else if ((i-1)%2 == 0) cout << range(SegtreeEven, 1, 0, n1-1, (i-1)/2, (v-1)/2) << "\n";
      else cout << range(SegtreeOdd, 1, 0, n2-1, (i-1)/2, (v-1)/2) << "\n";
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 456 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 10188 KB Output is correct
2 Correct 117 ms 10192 KB Output is correct
3 Correct 139 ms 10364 KB Output is correct
4 Correct 102 ms 9856 KB Output is correct
5 Correct 109 ms 9860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 456 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 117 ms 10188 KB Output is correct
16 Correct 117 ms 10192 KB Output is correct
17 Correct 139 ms 10364 KB Output is correct
18 Correct 102 ms 9856 KB Output is correct
19 Correct 109 ms 9860 KB Output is correct
20 Correct 123 ms 9976 KB Output is correct
21 Correct 109 ms 9984 KB Output is correct
22 Correct 117 ms 9976 KB Output is correct
23 Correct 108 ms 9908 KB Output is correct
24 Correct 109 ms 9856 KB Output is correct