結果

問題 No.1209 XOR Into You
ユーザー kumatan400kumatan400
提出日時 2021-10-25 19:30:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 132,012 KB
最終ジャッジ日時 2024-04-14 15:52:37
合計ジャッジ時間 9,016 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,928 KB
testcase_01 AC 37 ms
52,916 KB
testcase_02 AC 37 ms
53,292 KB
testcase_03 AC 37 ms
52,696 KB
testcase_04 AC 126 ms
118,968 KB
testcase_05 AC 126 ms
119,212 KB
testcase_06 AC 126 ms
119,360 KB
testcase_07 AC 218 ms
120,228 KB
testcase_08 AC 195 ms
106,216 KB
testcase_09 AC 197 ms
106,488 KB
testcase_10 AC 164 ms
97,744 KB
testcase_11 AC 195 ms
106,272 KB
testcase_12 AC 181 ms
103,056 KB
testcase_13 AC 200 ms
115,820 KB
testcase_14 AC 175 ms
102,788 KB
testcase_15 AC 182 ms
103,224 KB
testcase_16 AC 186 ms
103,124 KB
testcase_17 AC 177 ms
102,700 KB
testcase_18 AC 239 ms
129,492 KB
testcase_19 AC 182 ms
103,400 KB
testcase_20 AC 205 ms
115,884 KB
testcase_21 AC 161 ms
97,660 KB
testcase_22 AC 176 ms
131,524 KB
testcase_23 AC 174 ms
131,648 KB
testcase_24 AC 176 ms
131,492 KB
testcase_25 AC 198 ms
131,640 KB
testcase_26 AC 200 ms
132,012 KB
testcase_27 AC 201 ms
131,644 KB
testcase_28 AC 200 ms
131,768 KB
testcase_29 AC 196 ms
131,512 KB
testcase_30 AC 198 ms
131,888 KB
testcase_31 AC 161 ms
107,820 KB
testcase_32 AC 159 ms
107,968 KB
testcase_33 AC 163 ms
107,832 KB
testcase_34 AC 163 ms
108,952 KB
testcase_35 AC 161 ms
107,940 KB
testcase_36 AC 161 ms
107,832 KB
testcase_37 AC 152 ms
113,412 KB
testcase_38 AC 172 ms
120,000 KB
testcase_39 AC 156 ms
106,096 KB
testcase_40 AC 175 ms
131,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class fenwick_tree():
    n=1
    data=[0 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.data=[0 for i in range(N)]
    def add(self,p,x):
        assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n)
        p+=1
        while(p<=self.n):
            self.data[p-1]+=x
            p+=p& -p
    def sum(self,l,r):
        assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n)
        return self.sum0(r)-self.sum0(l)
    def sum0(self,r):
        s=0
        while(r>0):
            s+=self.data[r-1]
            r-=r&-r
        return s


N = int(input())
A = list(map(int, input().split())) + [0]
B = list(map(int, input().split())) + [0]

A2 = []
for i in range(N):
    A2.append(A[i]^A[i+1])

B2 = []
for i in range(N):
    B2.append(B[i]^B[i+1])

bit = fenwick_tree(N+1)

M = {}
for b in B2:
    M[b] = []
for i, b in enumerate(B2):
    M[b].append(i)


ans = 0
for i in range(N-1, -1, -1):
    a = A2[i]

    if not a in M or not M[a]:
        print(-1)
        exit()

    p = M[a][-1] + 1

    ans += bit.sum0(p)
    bit.add(p, 1)
    M[a].pop()
print(ans)




0