結果

問題 No.1209 XOR Into You
ユーザー kutaragi36kutaragi36
提出日時 2023-07-02 14:08:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 165,968 KB
最終ジャッジ日時 2023-09-23 10:32:18
合計ジャッジ時間 18,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,848 KB
testcase_01 AC 76 ms
71,584 KB
testcase_02 AC 97 ms
71,840 KB
testcase_03 AC 96 ms
71,820 KB
testcase_04 AC 127 ms
94,244 KB
testcase_05 AC 119 ms
94,396 KB
testcase_06 AC 156 ms
95,768 KB
testcase_07 AC 357 ms
150,388 KB
testcase_08 AC 320 ms
142,656 KB
testcase_09 AC 309 ms
142,848 KB
testcase_10 AC 266 ms
128,452 KB
testcase_11 AC 304 ms
140,780 KB
testcase_12 AC 285 ms
138,716 KB
testcase_13 AC 320 ms
144,756 KB
testcase_14 AC 281 ms
137,580 KB
testcase_15 AC 292 ms
139,860 KB
testcase_16 AC 290 ms
138,976 KB
testcase_17 AC 282 ms
136,892 KB
testcase_18 AC 363 ms
162,832 KB
testcase_19 AC 288 ms
139,260 KB
testcase_20 AC 320 ms
144,980 KB
testcase_21 AC 260 ms
127,340 KB
testcase_22 AC 290 ms
165,776 KB
testcase_23 AC 290 ms
165,772 KB
testcase_24 AC 287 ms
165,968 KB
testcase_25 AC 328 ms
165,676 KB
testcase_26 AC 328 ms
165,544 KB
testcase_27 AC 328 ms
165,804 KB
testcase_28 AC 330 ms
165,660 KB
testcase_29 AC 329 ms
165,776 KB
testcase_30 AC 322 ms
165,968 KB
testcase_31 AC 229 ms
100,408 KB
testcase_32 AC 232 ms
100,544 KB
testcase_33 AC 232 ms
100,412 KB
testcase_34 AC 232 ms
101,408 KB
testcase_35 AC 227 ms
100,604 KB
testcase_36 AC 230 ms
100,456 KB
testcase_37 AC 195 ms
99,756 KB
testcase_38 AC 294 ms
150,352 KB
testcase_39 AC 272 ms
141,072 KB
testcase_40 AC 283 ms
165,728 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]:
    print(-1)
    exit()

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

if sorted(X) != sorted(Y):
    print(-1)
    exit()

import collections
C = collections.defaultdict(collections.deque)
for i, y in enumerate(Y):
    C[y].append(i)

Z = []
for x in X:
    Z.append(C[x].popleft())

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

print(ans)
0