Submission #1068865

# Submission time Handle Problem Language Result Execution time Memory
1068865 2024-08-21T12:38:59 Z adrielcp XORanges (eJOI19_xoranges) C++17
100 / 100
387 ms 17672 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout << #x << " " << (x) << endl;
#define all(x) x.begin(), x.end()
void pp(pair<int, int>&a) { cout << "{" << a.first << ", " << a.second << endl; }
void g(vector<int>&a) { cout << "{"; for (auto el : a) cout << el << ", "; cout << "}" << endl; }
void g(vector<pair<int, int>>&a) { cout << "{"; for (auto el : a) pp(el); cout << "}" << endl; }
// #define DBG

struct Seg {
  vector<int> seg, a;
  Seg(vector<int> &b) {
    a = b;
    seg = vector<int>(a.size()*4);
  }

  void build(int idx, int l, int r) {
    if (l == r) seg[idx] = a[l];
    else {
      int mid = (l+r)>>1;
      build(idx*2, l, mid);
      build(idx*2+1, mid+1, r);
      seg[idx] = seg[idx*2] ^ seg[idx*2+1];
    }
  }

  int query(int idx, int l, int r, int ql, int qr) {
    if (l > qr || r < ql || l > r) return 0;
    if (l >= ql && r <= qr) return seg[idx];
    int mid = (l+r)>>1;
    return query(idx*2, l, mid, ql, qr) ^ query(idx*2+1, mid+1, r, ql, qr);
  }

  void update(int idx, int l, int r, int i, int v) {
    if (l == r) seg[idx] = v;
    else {
      int mid = (l+r)>>1;
      if (i <= mid) update(idx*2, l, mid, i, v);
      else update(idx*2+1, mid+1, r, i, v);
      seg[idx] = seg[idx*2] ^ seg[idx*2+1];
    }
  } 
};

void solve() {
  int n,q;cin>>n>>q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  // even
  // 2 4 6 8 
  // 1 2 3 4
  // x/2

  // 1 3 5 7 9 10 (odd)
  // 1 2 3 4 5 6
  // x/2 + 1
  vector<int> odd{0}, even{0};
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) odd.push_back(a[i]);
    else even.push_back(a[i]);
  }
  Seg seg_odd(odd), seg_even(even);
  seg_odd.build(1, 1, odd.size());
  seg_even.build(1, 1, even.size());

  while (q--) {
    int t,x,y;cin>>t>>x>>y;
    if (t==1) {
      // upd
      // update(1, 1, n, x, y);
      if (x % 2 == 0) seg_even.update(1, 1, even.size(), x/2, y);
      else seg_odd.update(1, 1, odd.size(), x/2+1, y);
    } else {
      if ((y-x+1) % 2 == 0) cout << 0 << endl;
      else {
        if (x % 2 == 0) cout << seg_even.query(1, 1, even.size(), x/2, y/2) << endl;
        else cout << seg_odd.query(1, 1, odd.size(), x/2+1, y/2+1) << endl;
      }
    }
  }

  // g(a);
}

int32_t main() {
  ios_base::sync_with_stdio(0);cin.tie(NULL);
  int t=1;
  #ifdef DBG
  freopen("inp1.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  cin>>t;
  #endif
  while (t--) {
    solve();
    cout << endl;
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 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 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 13 ms 884 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 17672 KB Output is correct
2 Correct 312 ms 17524 KB Output is correct
3 Correct 302 ms 17600 KB Output is correct
4 Correct 299 ms 17096 KB Output is correct
5 Correct 337 ms 17144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 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 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 13 ms 884 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 318 ms 17672 KB Output is correct
16 Correct 312 ms 17524 KB Output is correct
17 Correct 302 ms 17600 KB Output is correct
18 Correct 299 ms 17096 KB Output is correct
19 Correct 337 ms 17144 KB Output is correct
20 Correct 190 ms 17340 KB Output is correct
21 Correct 180 ms 17320 KB Output is correct
22 Correct 206 ms 17228 KB Output is correct
23 Correct 315 ms 17340 KB Output is correct
24 Correct 387 ms 17092 KB Output is correct