結果

問題 No.1209 XOR Into You
ユーザー kumatan400kumatan400
提出日時 2021-10-25 19:27:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,123 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 130,476 KB
最終ジャッジ日時 2024-04-14 15:48:17
合計ジャッジ時間 10,119 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,460 KB
testcase_01 AC 39 ms
54,024 KB
testcase_02 AC 38 ms
53,044 KB
testcase_03 AC 37 ms
52,952 KB
testcase_04 AC 122 ms
117,336 KB
testcase_05 WA -
testcase_06 AC 122 ms
117,448 KB
testcase_07 AC 216 ms
118,688 KB
testcase_08 AC 190 ms
106,344 KB
testcase_09 AC 188 ms
106,872 KB
testcase_10 AC 159 ms
96,952 KB
testcase_11 AC 186 ms
106,232 KB
testcase_12 AC 176 ms
102,920 KB
testcase_13 AC 199 ms
114,704 KB
testcase_14 AC 174 ms
102,892 KB
testcase_15 AC 177 ms
103,180 KB
testcase_16 AC 174 ms
103,020 KB
testcase_17 AC 172 ms
102,684 KB
testcase_18 AC 238 ms
128,180 KB
testcase_19 AC 175 ms
103,436 KB
testcase_20 AC 200 ms
114,508 KB
testcase_21 AC 158 ms
96,624 KB
testcase_22 AC 171 ms
130,476 KB
testcase_23 AC 171 ms
129,984 KB
testcase_24 AC 169 ms
129,856 KB
testcase_25 AC 193 ms
130,376 KB
testcase_26 AC 191 ms
130,088 KB
testcase_27 AC 196 ms
130,116 KB
testcase_28 AC 195 ms
129,996 KB
testcase_29 AC 194 ms
130,100 KB
testcase_30 AC 191 ms
130,000 KB
testcase_31 AC 153 ms
106,292 KB
testcase_32 AC 157 ms
106,528 KB
testcase_33 AC 156 ms
106,160 KB
testcase_34 AC 158 ms
107,296 KB
testcase_35 AC 156 ms
106,280 KB
testcase_36 AC 154 ms
106,144 KB
testcase_37 AC 148 ms
111,616 KB
testcase_38 AC 170 ms
118,588 KB
testcase_39 AC 154 ms
106,068 KB
testcase_40 AC 169 ms
129,848 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()))

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

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

bit = fenwick_tree(N)

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


ans = 0
for i in range(N-2, -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