結果

問題 No.1493 隣接xor
ユーザー convexineqconvexineq
提出日時 2021-05-01 04:34:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 130,524 KB
最終ジャッジ日時 2023-09-26 13:02:05
合計ジャッジ時間 10,841 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,276 KB
testcase_01 AC 70 ms
71,284 KB
testcase_02 AC 72 ms
71,336 KB
testcase_03 AC 315 ms
130,224 KB
testcase_04 AC 315 ms
130,256 KB
testcase_05 AC 319 ms
130,088 KB
testcase_06 AC 324 ms
130,224 KB
testcase_07 AC 316 ms
127,988 KB
testcase_08 AC 314 ms
130,524 KB
testcase_09 AC 310 ms
130,284 KB
testcase_10 AC 310 ms
130,220 KB
testcase_11 AC 303 ms
130,264 KB
testcase_12 AC 318 ms
130,188 KB
testcase_13 AC 220 ms
117,788 KB
testcase_14 AC 200 ms
110,932 KB
testcase_15 AC 72 ms
71,336 KB
testcase_16 AC 73 ms
71,472 KB
testcase_17 AC 73 ms
71,336 KB
testcase_18 AC 74 ms
71,388 KB
testcase_19 AC 74 ms
71,468 KB
testcase_20 AC 208 ms
96,720 KB
testcase_21 AC 231 ms
99,556 KB
testcase_22 AC 189 ms
96,320 KB
testcase_23 AC 213 ms
96,860 KB
testcase_24 AC 314 ms
129,320 KB
testcase_25 AC 184 ms
94,660 KB
testcase_26 AC 234 ms
100,044 KB
testcase_27 AC 153 ms
87,956 KB
testcase_28 AC 291 ms
122,608 KB
testcase_29 AC 230 ms
99,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segment_tree:
    __slots__ = ["op_M", "e_M","N","N0","dat"]
    def __init__(self, N, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        self.N = N
        self.N0 = 1<<(N-1).bit_length()
        self.dat = [self.e_M]*(2*self.N0)
    
    # 長さNの配列 initial で初期化
    def build(self, initial):
        assert self.N == len(initial)
        self.dat[self.N0:self.N0+len(initial)] = initial[:]
        for k in range(self.N0-1,0,-1):
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])

    # a_k の値を x に更新
    def update(self,k,x):
        k += self.N0
        self.dat[k] = x
        k >>= 1
        while k:
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])
            k >>= 1

    # 区間[L,R]をopでまとめる
    def query(self,L,R):
        L += self.N0; R += self.N0 + 1 
        sl = sr = self.e_M
        while L < R:
            if R & 1:
                R -= 1
                sr = self.op_M(self.dat[R],sr)
            if L & 1:
                sl = self.op_M(sl,self.dat[L])
                L += 1
            L >>= 1; R >>= 1
        return self.op_M(sl,sr)

    def get(self, k): #k番目の値を取得。query[k,k]と同じ
        return self.dat[k+self.N0]
    
n = int(input())
*a, = map(int,input().split())
for i in range(1,n): a[i] ^= a[i-1]
a = a[::-1]
from operator import add
seg = segment_tree(n,add,0)
seg.build([1]+[0]*(n-1))
pos = {}
MOD = 10**9+7
for i in range(1,n):
    idx = pos[a[i]] if a[i] in pos else 0
    pos[a[i]] = i
    v = seg.query(idx,i)
    seg.update(i,v%MOD)
print(seg.query(0,n-1)%MOD)
0