답안 #943745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
943745 2024-03-11T19:45:26 Z stefanneagu XORanges (eJOI19_xoranges) C++17
0 / 100
1 ms 860 KB
#include <iostream>

using namespace std;

const int nmax = 5001;

int f[101];

struct AINT {
  int aint[nmax * 4];

  void update(int nod, int st, int dr, int poz, int val) {
    if(st == dr) {
      aint[nod] = val;
      return;
    }
    int mid = (st + dr) / 2;
    if(poz <= mid) {
      update(nod << 1, st, mid, poz, val);
    } else {
      update(nod << 1 + 1, mid + 1, dr, poz, val);
    }
    aint[nod] = (aint[nod << 1] ^ aint[nod << 1 + 1]);
  }

  int query(int nod, int st, int dr, int l, int r) {
    if(l <= st && dr <= r) {
      return aint[nod];
    }
    int mid = (st + dr) / 2, a1 = 0, a2 = 0;
    if(l <= mid) {
      a1 = query(nod << 1, st, mid, l, min(r, mid));
    }
    if(r > mid) {
      a2 = query(nod << 1 + 1, mid + 1, dr, max(l, mid + 1), r);
    }
    return (a1 ^ a2);
  }
};

int main() {
  AINT s1, s2;
  int n, q;
  cin >> n >> q;
  for(int i = 1; i <= n; i ++) {
    int a;
    cin >> a;
    if(i % 2 == 0) {
      s1.update(1, 1, n / 2 + 1, i / 2, a);
    } else {
      s2.update(1, 1, n / 2 + 1, i / 2 + 1, a);
    }
  }
  for(int i = 1; i <= q; i ++) {
    int t, a, b;
    cin >> t >> a >> b;
    if(t == 1) {
      if(a % 2 == 0) {
        s1.update(1, 1, n / 2 + 1, a / 2, b);
      } else {
        s2.update(1, 1, n / 2 + 1, a / 2 + 1, b);
      }
    } else {
      if((b - a + 1) % 2 == 0) {
        cout << "0\n";
      } else if(a % 2 == 0) {
        cout << s1.query(1, 1, n / 2 + 1, a / 2, b / 2) << '\n';
      } else {
        cout << s2.query(1, 1, n / 2 + 1, a / 2 + 1, b / 2 + 1) << '\n';
      }
    }
    /*
    cout << "sirul: ";
    for(int ii = 1; ii <= n; ii ++) {
      if(ii % 2 == 0) {
        cout << s1.query(1, 1, n / 2 + 1, ii / 2, ii / 2) << " ";
      } else {
        cout << s2.query(1, 1, n / 2 + 1, ii / 2 + 1, ii / 2 + 1) << " ";
      }
    }
    cout << '\n';
    */
  }
  return 0;
}

Compilation message

xoranges.cpp: In member function 'void AINT::update(int, int, int, int, int)':
xoranges.cpp:21:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   21 |       update(nod << 1 + 1, mid + 1, dr, poz, val);
      |                     ~~^~~
xoranges.cpp:23:49: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   23 |     aint[nod] = (aint[nod << 1] ^ aint[nod << 1 + 1]);
      |                                               ~~^~~
xoranges.cpp: In member function 'int AINT::query(int, int, int, int, int)':
xoranges.cpp:35:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   35 |       a2 = query(nod << 1 + 1, mid + 1, dr, max(l, mid + 1), r);
      |                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -