結果

問題 No.1091 Range Xor Query
ユーザー tonnnura172tonnnura172
提出日時 2020-06-24 03:56:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 2,649 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 115,832 KB
最終ジャッジ日時 2023-09-16 20:42:22
合計ジャッジ時間 12,095 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
80,376 KB
testcase_01 AC 170 ms
80,340 KB
testcase_02 AC 169 ms
80,108 KB
testcase_03 AC 252 ms
98,436 KB
testcase_04 AC 317 ms
89,668 KB
testcase_05 AC 357 ms
114,224 KB
testcase_06 AC 197 ms
84,968 KB
testcase_07 AC 341 ms
98,896 KB
testcase_08 AC 403 ms
100,628 KB
testcase_09 AC 297 ms
88,824 KB
testcase_10 AC 344 ms
103,304 KB
testcase_11 AC 387 ms
109,528 KB
testcase_12 AC 321 ms
109,696 KB
testcase_13 AC 405 ms
101,000 KB
testcase_14 AC 362 ms
103,004 KB
testcase_15 AC 372 ms
109,568 KB
testcase_16 AC 344 ms
91,384 KB
testcase_17 AC 409 ms
107,468 KB
testcase_18 AC 238 ms
84,420 KB
testcase_19 AC 257 ms
100,752 KB
testcase_20 AC 397 ms
100,672 KB
testcase_21 AC 288 ms
88,496 KB
testcase_22 AC 392 ms
105,488 KB
testcase_23 AC 336 ms
115,464 KB
testcase_24 AC 338 ms
115,832 KB
testcase_25 AC 337 ms
115,564 KB
testcase_26 AC 343 ms
115,824 KB
testcase_27 AC 335 ms
115,640 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