Submission #21422232


Source Code Expand

size, q = map(int, input().split())
a = list(map(int, input().split()))

#葉の数がlistのサイズ以上になるように完全2分木を作る。
n = 1
while n < size:
    n *= 2
node = [0]*(2*n-1)

#n-1, ..., n+size-2にaを入れる。n+size-1, ..., 2n-2は0(xorでの単位元)で、影響を与えない。
for i in range(size):
    node[i+n-1] = a[i]
#node[i] = node[2i+1]^node[2i+2]で、葉以外のノードであるnode[n-2], ..., node[0]を更新して行く
for i in range(n-2, -1, -1):
    node[i] = node[2*i+1] ^ node[2*i+2]


def update(i, x): #a[i]をxで更新する
    i += n-1
    node[i] = x
    while i > 0:
        i = (i-1)//2 #2i+1, 2i+2(子ノード)からi(親ノード)に行くには、1引いて2で切り捨て割り算すればok
        node[i] = node[2*i+1] ^ node[2*i+2]

def fold(L, R): #a[L]^a[L+1]^...^a[R-1]を出力する
    L += n-1
    R += n-1
    vL = 0
    vR = 0
    while R > L:
        if L % 2 == 0:
            vL ^= node[L]
            L += 1
        if R % 2 == 0:
            vR ^= node[R-1]
        L = (L-1)//2
        R = (R-1)//2
    return (vL^vR)

ret = []
for i in range(q):
    t, x, y = map(int, input().split())
    x -= 1    
    if t == 1:
        update(x, node[x+n-1]^y)
    else:
        ret.append(fold(x, y))
    
for v in ret:
    print(v)

Submission Info

Submission Time
Task F - Range Xor Query
User Arcamon
Language Python (3.8.2)
Score 600
Code Size 1367 Byte
Status AC
Exec Time 2797 ms
Memory 50964 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All handmade_00.txt, handmade_01.txt, max_00.txt, max_01.txt, max_02.txt, max_03.txt, max_04.txt, max_05.txt, max_06.txt, max_07.txt, power_of_2_00.txt, power_of_2_01.txt, power_of_2_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
handmade_00.txt AC 22 ms 9084 KiB
handmade_01.txt AC 21 ms 9092 KiB
max_00.txt AC 2797 ms 49764 KiB
max_01.txt AC 2772 ms 50076 KiB
max_02.txt AC 2713 ms 49808 KiB
max_03.txt AC 2508 ms 50836 KiB
max_04.txt AC 2587 ms 50964 KiB
max_05.txt AC 1701 ms 50832 KiB
max_06.txt AC 2787 ms 47488 KiB
max_07.txt AC 2776 ms 47524 KiB
power_of_2_00.txt AC 2307 ms 41424 KiB
power_of_2_01.txt AC 2320 ms 41692 KiB
power_of_2_02.txt AC 2431 ms 45728 KiB
random_00.txt AC 2238 ms 24708 KiB
random_01.txt AC 1548 ms 35928 KiB
random_02.txt AC 385 ms 11164 KiB
random_03.txt AC 2033 ms 34996 KiB
random_04.txt AC 196 ms 10476 KiB
sample_01.txt AC 19 ms 9208 KiB
sample_02.txt AC 20 ms 9140 KiB