結果
| 問題 |
No.1091 Range Xor Query
|
| ユーザー |
|
| 提出日時 | 2020-06-25 23:03:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 2,000 ms |
| コード長 | 2,487 bytes |
| コンパイル時間 | 1,554 ms |
| コンパイル使用メモリ | 168,988 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-03 21:55:29 |
| 合計ジャッジ時間 | 8,900 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)
using ll = long long;
using ld = long double;
const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
template <typename T>
class SegmentTree {
public:
int n;
T e;
vector<T> node;
function<T(T, T)> operation;
function<T(T, T)> process;
SegmentTree() {}
SegmentTree(int n_, T e_, function<T(T, T)> operation_,
function<T(T, T)> process_) : e(e_), operation(operation_), process(process_) {
n = 1;
while (n < n_) n <<= 1;
node.assign(2 * n, e);
}
void build() {
for (int i = n - 1; i > 0; --i) {
node[i] = operation(node[i * 2 + 0], node[i * 2 + 1]);
}
}
void set(int idx, T v) {
node[idx + n] = process(node[idx + n], v);
}
void update(int idx, T v) {
idx += n;
node[idx] = process(node[idx], v);
while (idx >>= 1) {
node[idx] = operation(node[idx * 2 + 0], node[idx * 2 + 1]);
}
}
T query(int a, int b) {
return query(a, b + 1, 1, 0, n);
}
T query(int a, int b, int k, int l, int r) {
if (a >= r || b <= l) return e;
if (a <= l && b >= r) return node[k];
T c = query(a, b, 2 * k + 0, l, (l + r) / 2);
T d = query(a, b, 2 * k + 1, (l + r) / 2, r);
return operation(c, d);
}
T operator[](int idx) {
return node[idx + n];
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(0);
int n, q;
cin >> n >> q;
// SegmentTree<int> seg = SegmentTree<int>(n, 0,
// [](int a, int b) { return a ^ b; }, [](int a, int b) { return b; });
// rep (i, n) {
// int a;
// cin >> a;
// seg.set(i, a);
// }
// seg.build();
// rep (i, q) {
// int l, r;
// cin >> l >> r;
// cout << seg.query(l - 1, r - 1) << endl;
// }
vector<int> a(n + 1);
rep (i, n) cin >> a[i + 1];
rep (i, n) a[i + 1] ^= a[i];
rep (i, q) {
int l, r;
cin >> l >> r;
cout << (a[r] ^ a[l - 1]) << endl;
}
return 0;
}