結果

問題 No.1091 Range Xor Query
ユーザー lloyzlloyz
提出日時 2022-08-31 07:26:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 631 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 107,776 KB
最終ジャッジ日時 2024-04-25 12:18:35
合計ジャッジ時間 16,042 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
52,352 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 172 ms
94,720 KB
testcase_04 AC 417 ms
80,128 KB
testcase_05 AC 461 ms
107,264 KB
testcase_06 AC 87 ms
79,104 KB
testcase_07 AC 444 ms
89,984 KB
testcase_08 AC 601 ms
95,104 KB
testcase_09 AC 341 ms
81,024 KB
testcase_10 AC 446 ms
97,792 KB
testcase_11 AC 562 ms
103,552 KB
testcase_12 AC 357 ms
103,808 KB
testcase_13 AC 631 ms
92,800 KB
testcase_14 AC 478 ms
97,408 KB
testcase_15 AC 499 ms
103,424 KB
testcase_16 AC 479 ms
81,408 KB
testcase_17 AC 628 ms
100,480 KB
testcase_18 AC 178 ms
77,824 KB
testcase_19 AC 198 ms
92,288 KB
testcase_20 AC 620 ms
92,160 KB
testcase_21 AC 334 ms
77,312 KB
testcase_22 AC 589 ms
100,096 KB
testcase_23 AC 602 ms
107,776 KB
testcase_24 AC 605 ms
107,520 KB
testcase_25 AC 591 ms
107,392 KB
testcase_26 AC 597 ms
107,392 KB
testcase_27 AC 603 ms
107,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Fenwick_Tree:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def add(self, p, x):
        p += 1
        while p <= self.n:
            self.data[p] ^= x
            p += p & -p

    def sum(self, l, r):
        '''範囲[l, r)(lからrまで)の総xorを求める'''
        return self._sum(r) ^ self._sum(l - 1)

    def _sum(self, r):
        '''範囲[0, r)(0からrまで)の総xorを求める'''
        s = 0
        r += 1
        while r > 0:
            s ^= self.data[r]
            r -= r & -r
        return s

n, q = map(int, input().split())
A = list(map(int, input().split()))
FT = Fenwick_Tree(n)
for i in range(n):
    FT.add(i, A[i])
for _ in range(q):
    l, r = map(int, input().split())
    print(FT.sum(l - 1, r - 1))
0