結果

問題 No.1091 Range Xor Query
ユーザー granddaifukugranddaifuku
提出日時 2020-06-25 23:03:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 2,487 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 165,844 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-16 23:08:31
合計ジャッジ時間 9,328 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 30 ms
4,380 KB
testcase_04 AC 190 ms
4,384 KB
testcase_05 AC 185 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 203 ms
4,380 KB
testcase_08 AC 284 ms
4,376 KB
testcase_09 AC 141 ms
4,384 KB
testcase_10 AC 191 ms
4,384 KB
testcase_11 AC 251 ms
4,376 KB
testcase_12 AC 133 ms
4,380 KB
testcase_13 AC 306 ms
4,380 KB
testcase_14 AC 205 ms
4,380 KB
testcase_15 AC 222 ms
4,380 KB
testcase_16 AC 237 ms
4,376 KB
testcase_17 AC 299 ms
4,376 KB
testcase_18 AC 47 ms
4,376 KB
testcase_19 AC 48 ms
4,376 KB
testcase_20 AC 291 ms
4,380 KB
testcase_21 AC 145 ms
4,376 KB
testcase_22 AC 268 ms
4,376 KB
testcase_23 AC 314 ms
4,380 KB
testcase_24 AC 315 ms
4,384 KB
testcase_25 AC 308 ms
4,380 KB
testcase_26 AC 311 ms
4,376 KB
testcase_27 AC 308 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0