結果

問題 No.1209 XOR Into You
ユーザー kumatan400kumatan400
提出日時 2022-09-12 18:16:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 118,204 KB
最終ジャッジ日時 2023-08-19 21:54:25
合計ジャッジ時間 12,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,832 KB
testcase_01 AC 71 ms
71,256 KB
testcase_02 AC 71 ms
71,244 KB
testcase_03 AC 70 ms
71,324 KB
testcase_04 AC 119 ms
93,880 KB
testcase_05 AC 113 ms
94,136 KB
testcase_06 AC 151 ms
95,304 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 170 ms
93,592 KB
testcase_22 AC 186 ms
116,692 KB
testcase_23 AC 184 ms
116,684 KB
testcase_24 AC 180 ms
116,888 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 153 ms
101,028 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 181 ms
116,792 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()




X = {}
c = 0
for b in B:
    if b in X:
        continue
    X[b] = c
    c += 1

A = [X[a] for a in A]
FT = fenwick_tree(N-1)

ans = 0
for a in A[::-1]:
    ans += FT.sum0(a)
    FT.add(a, 1)
print(ans)



0