結果

問題 No.1091 Range Xor Query
ユーザー tonnnura172tonnnura172
提出日時 2020-06-24 03:56:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 308 ms / 2,000 ms
コード長 2,649 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 112,908 KB
最終ジャッジ日時 2024-07-03 19:53:09
合計ジャッジ時間 8,662 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
65,792 KB
testcase_01 AC 62 ms
66,304 KB
testcase_02 AC 63 ms
66,688 KB
testcase_03 AC 150 ms
94,592 KB
testcase_04 AC 218 ms
85,468 KB
testcase_05 AC 251 ms
111,388 KB
testcase_06 AC 97 ms
81,408 KB
testcase_07 AC 237 ms
94,692 KB
testcase_08 AC 289 ms
96,456 KB
testcase_09 AC 194 ms
84,736 KB
testcase_10 AC 246 ms
100,352 KB
testcase_11 AC 281 ms
107,544 KB
testcase_12 AC 225 ms
107,652 KB
testcase_13 AC 292 ms
95,648 KB
testcase_14 AC 255 ms
100,224 KB
testcase_15 AC 270 ms
106,956 KB
testcase_16 AC 239 ms
87,184 KB
testcase_17 AC 308 ms
104,248 KB
testcase_18 AC 136 ms
80,200 KB
testcase_19 AC 157 ms
93,396 KB
testcase_20 AC 298 ms
96,640 KB
testcase_21 AC 187 ms
84,480 KB
testcase_22 AC 296 ms
102,928 KB
testcase_23 AC 234 ms
112,824 KB
testcase_24 AC 237 ms
112,716 KB
testcase_25 AC 236 ms
112,640 KB
testcase_26 AC 238 ms
112,908 KB
testcase_27 AC 239 ms
112,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class SegmentTree:
    """Segment Tree (Point Update & Range Query)
    Query
        1. update(i, val): update i-th value(0-indexed) to val
        2. query(low, high): find f(value) in [low, high)
    Complexity
        time complexity: O(log n)
        space complexity: O(n)
    """
    def __init__(self, N, f, default):
        self.N = 1 << (N-1).bit_length()
        self.default = default
        self.f = f
        self.segtree = [self.default] * ((self.N << 1) - 1)
    @classmethod
    def create_from_array(cls, arr, f, default):
        N = len(arr)
        self = cls(N, f, default)
        for i in range(N):
            self.segtree[self.N - 1 + i] = arr[i]
        for i in reversed(range(self.N - 1)):
            self.segtree[i] = self.f(
                self.segtree[(i << 1) + 1], self.segtree[(i << 1) + 2])
        return self
    def update(self, i, val):  # update
        i += self.N - 1
        self.segtree[i] = val
        while i > 0:
            i = (i - 1) >> 1
            self.segtree[i] = self.f(
                self.segtree[(i << 1)+1], self.segtree[(i << 1)+2])
    def query(self, low, high):  # query
        # query [l, r)
        low, high = low + self.N, high + self.N
        ret = self.default
        while low < high:
            if low & 1:
                ret = self.f(ret, self.segtree[low-1])
                low += 1
            if high & 1:
                high -= 1
                ret = self.f(ret, self.segtree[high-1])
            low, high = low >> 1, high >> 1
        return ret
    def get(self, k):  # get k-th value(0-indexed)
        return self.segtree[k+self.N-1]
    def all(self):  # all range query
        return self.segtree[0]

N, Q = MAP()
a = LIST()
xor = lambda x,y:x^y
st = SegmentTree.create_from_array(a, xor, 0)

ans = [0]*Q
for i in range(Q):
    l, r = MAP()
    ans[i] = st.query(l-1, r)

print(*ans, sep="\n")
0