답안 #1070830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070830 2024-08-22T19:14:05 Z matthew XORanges (eJOI19_xoranges) C++17
38 / 100
96 ms 8784 KB
#include <stdio.h>

const int MAXN = 200'000;

int v[MAXN + 1];

// poate fi optimizat la un singur N de memorie
int aib_par[MAXN + 1];
int aib_impar[MAXN + 1];

void pointUpdate(int *aib, int pos, int delta, int n) {
  while(pos <= n) {
    aib[pos] ^= delta;
    pos += pos & -pos;
  }
}

int prefixQuery(int *aib, int pos) {
  int res = 0;
  while(pos > 0) {
    res ^= aib[pos];
    pos &= pos - 1;
  }
  return res;
}

static inline int rangeQuery(int *aib, int l, int r) {
  return prefixQuery(aib, r) ^ prefixQuery(aib, l - 1);
}

int main() {
  #ifdef LOCAL
freopen("input.txt", "r", stdin);
  #endif

  int n, q, i, l, r, type, pos, val;

  scanf("%d%d", &n, &q);
  for(i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    pointUpdate((i & 1) ? aib_impar : aib_par, i, v[i], n);
  }

  for(i = 0; i < q; i++) {
    scanf("%d", &type);

    if(type == 2) {
      scanf("%d%d", &l, &r);

      if((r - l) & 1) {
        printf("0\n");
      } else {
        printf("%d\n", rangeQuery((l & 1) ? aib_impar : aib_par, l, r));
      }
    } else {
      scanf("%d%d", &pos, &val);
      pointUpdate((pos & 1) ? aib_impar : aib_par, pos, v[pos] ^ val, n);
    }
  }

  return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &n, &q);
      |   ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d", &v[i]);
      |     ~~~~~^~~~~~~~~~~~~
xoranges.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d", &type);
      |     ~~~~~^~~~~~~~~~~~~
xoranges.cpp:48:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |       scanf("%d%d", &l, &r);
      |       ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:56:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |       scanf("%d%d", &pos, &val);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 8784 KB Output is correct
2 Correct 69 ms 8532 KB Output is correct
3 Correct 69 ms 8656 KB Output is correct
4 Correct 73 ms 8380 KB Output is correct
5 Correct 73 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -