結果

問題 No.1091 Range Xor Query
ユーザー tnakao0123tnakao0123
提出日時 2020-06-24 18:10:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 93,040 KB
実行使用メモリ 5,452 KB
最終ジャッジ日時 2023-09-16 21:09:39
合計ジャッジ時間 5,559 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 22 ms
4,476 KB
testcase_04 AC 79 ms
4,376 KB
testcase_05 AC 92 ms
5,356 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 89 ms
4,544 KB
testcase_08 AC 127 ms
4,656 KB
testcase_09 AC 56 ms
4,376 KB
testcase_10 AC 89 ms
5,240 KB
testcase_11 AC 114 ms
5,204 KB
testcase_12 AC 71 ms
5,228 KB
testcase_13 AC 141 ms
4,724 KB
testcase_14 AC 98 ms
5,108 KB
testcase_15 AC 107 ms
5,152 KB
testcase_16 AC 96 ms
4,380 KB
testcase_17 AC 136 ms
5,228 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 28 ms
4,516 KB
testcase_20 AC 127 ms
4,392 KB
testcase_21 AC 59 ms
4,380 KB
testcase_22 AC 124 ms
5,060 KB
testcase_23 AC 83 ms
5,336 KB
testcase_24 AC 83 ms
5,340 KB
testcase_25 AC 82 ms
5,452 KB
testcase_26 AC 83 ms
5,340 KB
testcase_27 AC 82 ms
5,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1091.cc:  No.1091 Range Xor Query - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000100;
const int MAX_E2 = 1 << 19; // = 524288

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

template <typename T, const int MAX_E2>
struct SegTreeXor {
  int e2;
  T nodes[MAX_E2];
  SegTreeXor() {}

  void init(int n) {
    for (e2 = 1; e2 < n; e2 <<= 1);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { get(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = nodes[j * 2 + 1] ^ nodes[j * 2 + 2];
  }

  T xor_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return 0;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = xor_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = xor_range(r0, r1, k * 2 + 2, im, i1);
    return v0 ^ v1;
  }
  T xor_range(int r0, int r1) { return xor_range(r0, r1, 0, 0, e2); }
};

/* global variables */

SegTreeXor<int,MAX_E2> st;

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  st.init(n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    st.seti(i, ai);
  }
  st.setall();

  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;

    printf("%d\n", st.xor_range(l, r));
  }
  return 0;
}
0