結果

問題 No.1493 隣接xor
ユーザー chineristACchineristAC
提出日時 2021-04-30 21:59:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 148,484 KB
最終ジャッジ日時 2023-09-26 06:04:41
合計ジャッジ時間 9,846 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
74,672 KB
testcase_01 AC 110 ms
74,428 KB
testcase_02 AC 111 ms
74,212 KB
testcase_03 AC 362 ms
148,148 KB
testcase_04 AC 357 ms
148,256 KB
testcase_05 AC 360 ms
148,180 KB
testcase_06 AC 364 ms
148,484 KB
testcase_07 AC 361 ms
148,060 KB
testcase_08 AC 349 ms
148,092 KB
testcase_09 AC 357 ms
148,272 KB
testcase_10 AC 358 ms
147,940 KB
testcase_11 AC 357 ms
148,456 KB
testcase_12 AC 358 ms
148,116 KB
testcase_13 AC 327 ms
114,436 KB
testcase_14 AC 315 ms
110,028 KB
testcase_15 AC 109 ms
74,376 KB
testcase_16 AC 112 ms
74,384 KB
testcase_17 AC 111 ms
74,468 KB
testcase_18 AC 110 ms
74,360 KB
testcase_19 AC 110 ms
74,248 KB
testcase_20 AC 260 ms
104,552 KB
testcase_21 AC 258 ms
108,256 KB
testcase_22 AC 237 ms
106,216 KB
testcase_23 AC 257 ms
105,240 KB
testcase_24 AC 349 ms
147,680 KB
testcase_25 AC 230 ms
103,812 KB
testcase_26 AC 265 ms
108,704 KB
testcase_27 AC 202 ms
98,044 KB
testcase_28 AC 336 ms
141,596 KB
testcase_29 AC 275 ms
108,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.buffer.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 10**9 + 7

N = int(input())
A = li()

xor = [A[i] for i in range(N)]
for i in range(1,N):
    xor[i] ^= xor[i-1]

next_idx = [-1 for i in range(N+1)]
memo = {val:N for val in xor}
for i in range(N-1,-1,-1):
    val = xor[i]
    next_idx[i] = memo[val]
    memo[val] = i

dp = SegmentTree([0]*(N+1),lambda x,y:(x+y)%mod,0)
dp.update(0,1)
for i in range(1,N):
    pre_xor = xor[i-1]
    dp_val = dp.query(0,i+1)

    next = next_idx[i-1]
    dp.update(i,dp_val)
    if next+2<=N:
        dp.update(next+2,-dp_val)



print(dp.query(0,N+1))
0