結果

問題 No.1209 XOR Into You
コンテスト
ユーザー ああ
提出日時 2026-05-28 22:15:22
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 748 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 277 ms
コンパイル使用メモリ 85,760 KB
実行使用メモリ 160,544 KB
最終ジャッジ日時 2026-05-28 22:15:33
合計ジャッジ時間 9,890 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque

def aa(s):
    d=1
    while s<len(fen):
        if s&d:
            fen[s]+=1;s+=d
        d<<=1
def bb(s):
    res,d=0,1
    while s:
        if s&d:
            res+=fen[s];s-=d
        d<<=1
    return res

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()
for i in range(n-1):
    a[i]^=a[i+1]
    b[i]^=b[i+1]
v={}
for i in range(n-1):
    if b[i] in v:
        v[b[i]].append(i+1)
    else:
        v[b[i]]=deque([i+1])
c=[]
for i in range(n-1):
    if a[i] not in v or not v[a[i]]:
        print(-1);exit()
    c.append(v[a[i]].popleft())
fen=[0]*(n+1);ans=0
for i in range(len(c)):
    ans+=i-bb(c[i])
    aa(c[i])
print(ans)
0