답안 #255974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255974 2020-08-02T07:24:28 Z jdh XORanges (eJOI19_xoranges) C++17
100 / 100
181 ms 13464 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> segt0,segt1,a;
void build(int idx,int b,int e){
  if(b == e){
    if(b&1) segt1[idx] = a[b];
    else segt0[idx] = a[b];
    return;
  }
  int mid = (b+e)/2;
  build(2*idx,b,mid);
  build(2*idx+1,mid+1,e);
  segt0[idx] = segt0[2*idx]^segt0[2*idx+1];
  segt1[idx] = segt1[2*idx]^segt1[2*idx+1];
}
void update(int idx,int b,int e,int pos,int val){
  if(b == e){
    if(b&1) segt1[idx] = val;
    else segt0[idx] = val;
    return;
  }
  int mid = (b+e)/2;
  if(pos <= mid) update(2*idx,b,mid,pos,val);
  else update(2*idx+1,mid+1,e,pos,val);
  segt0[idx] = segt0[2*idx]^segt0[2*idx+1];
  segt1[idx] = segt1[2*idx]^segt1[2*idx+1];
}
int query0(int idx,int b,int e,int l,int r){
  if(r < b or e < l or r < l) return 0;
  if(l <= b and e <= r) return segt0[idx];
  int mid = (b+e)/2;
  int s1 = query0(2*idx,b,mid,l,min(mid,r));
  int s2 = query0(2*idx+1,mid+1,e,max(l,mid+1),r);
  return s1^s2;
}
int query1(int idx,int b,int e,int l,int r){
  if(r < b or e < l or r < l) return 0;
  if(l <= b and e <= r) return segt1[idx];
  int mid = (b+e)/2;
  int s1 = query1(2*idx,b,mid,l,min(mid,r));
  int s2 = query1(2*idx+1,mid+1,e,max(l,mid+1),r);
  return s1^s2;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,q;
  cin >> n >> q;
  segt0.resize(4*n+5);
  segt1.resize(4*n+5);
  a.resize(n+1);
  for(int i = 1; i <= n; ++i) cin >> a[i];
  build(1,1,n);
  while(q--){
    int op;
    cin >> op;
    if(op == 1){
      int pos,val;
      cin >> pos >> val;
      update(1,1,n,pos,val);
    }
    else{
      int l,r;
      cin >> l >> r;
      if((r-l)&1) cout << "0\n";
      else{
        if(l&1) cout << query1(1,1,n,l,r) << '\n';
        else cout << query0(1,1,n,l,r) << '\n';
      }
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 12320 KB Output is correct
2 Correct 164 ms 13464 KB Output is correct
3 Correct 174 ms 13432 KB Output is correct
4 Correct 146 ms 13048 KB Output is correct
5 Correct 144 ms 13060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 181 ms 12320 KB Output is correct
16 Correct 164 ms 13464 KB Output is correct
17 Correct 174 ms 13432 KB Output is correct
18 Correct 146 ms 13048 KB Output is correct
19 Correct 144 ms 13060 KB Output is correct
20 Correct 167 ms 13188 KB Output is correct
21 Correct 167 ms 13304 KB Output is correct
22 Correct 166 ms 13176 KB Output is correct
23 Correct 140 ms 13176 KB Output is correct
24 Correct 143 ms 13048 KB Output is correct