結果

問題 No.1209 XOR Into You
ユーザー kumatan400kumatan400
提出日時 2023-02-03 02:32:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 1,141 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 166,048 KB
最終ジャッジ日時 2023-09-15 06:49:04
合計ジャッジ時間 16,955 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,856 KB
testcase_01 AC 69 ms
71,436 KB
testcase_02 AC 89 ms
71,916 KB
testcase_03 AC 90 ms
71,616 KB
testcase_04 AC 109 ms
94,188 KB
testcase_05 AC 111 ms
94,096 KB
testcase_06 AC 150 ms
95,632 KB
testcase_07 AC 310 ms
150,676 KB
testcase_08 AC 293 ms
142,972 KB
testcase_09 AC 289 ms
142,908 KB
testcase_10 AC 244 ms
128,460 KB
testcase_11 AC 288 ms
141,328 KB
testcase_12 AC 271 ms
138,676 KB
testcase_13 AC 300 ms
144,972 KB
testcase_14 AC 272 ms
137,556 KB
testcase_15 AC 266 ms
139,928 KB
testcase_16 AC 265 ms
138,988 KB
testcase_17 AC 269 ms
136,692 KB
testcase_18 AC 340 ms
162,688 KB
testcase_19 AC 281 ms
139,140 KB
testcase_20 AC 303 ms
145,184 KB
testcase_21 AC 243 ms
127,792 KB
testcase_22 AC 274 ms
165,584 KB
testcase_23 AC 273 ms
165,596 KB
testcase_24 AC 271 ms
165,700 KB
testcase_25 AC 310 ms
165,656 KB
testcase_26 AC 308 ms
165,568 KB
testcase_27 AC 310 ms
166,048 KB
testcase_28 AC 314 ms
165,884 KB
testcase_29 AC 311 ms
165,764 KB
testcase_30 AC 322 ms
165,896 KB
testcase_31 AC 226 ms
100,556 KB
testcase_32 AC 223 ms
100,412 KB
testcase_33 AC 225 ms
100,388 KB
testcase_34 AC 224 ms
101,276 KB
testcase_35 AC 224 ms
100,532 KB
testcase_36 AC 220 ms
100,372 KB
testcase_37 AC 184 ms
99,764 KB
testcase_38 AC 280 ms
150,320 KB
testcase_39 AC 261 ms
140,964 KB
testcase_40 AC 277 ms
165,860 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()))
B = list(map(int, input().split()))

if A[0] != B[0] or A[-1] != B[-1]:
    print(-1)
    exit()

A = [A[i]^A[i+1] for i in range(N-1)]
B = [B[i]^B[i+1] for i in range(N-1)]

if sorted(A) != sorted(B):
    print(-1)
    exit()

import collections
X = collections.defaultdict(collections.deque)
for i, b in enumerate(B):
    X[b].append(i)

C = []
for a in A:
    C.append(X[a].popleft())

G = fenwick_tree(N)
ans = 0
for c in C[::-1]:
    ans += G.sum0(c)
    G.add(c, 1)

print(ans)
0