結果
問題 |
No.1209 XOR Into You
|
ユーザー |
![]() |
提出日時 | 2022-01-02 21:17:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 307 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 288 ms |
コンパイル使用メモリ | 82,008 KB |
実行使用メモリ | 145,480 KB |
最終ジャッジ日時 | 2024-10-12 01:27:53 |
合計ジャッジ時間 | 10,639 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
import sys import collections class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] += x i += i & -i N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) A2 = [0] * (N-1) B2 = [0] * (N-1) if A[0] != B[0] or A[-1] != B[-1]: print(-1) sys.exit() for i in range(N-1): A2[i] = A[i] ^ A[i+1] B2[i] = B[i] ^ B[i+1] if collections.Counter(A2) != collections.Counter(B2): print(-1) sys.exit() dic = {} for i,b in enumerate(B2,1): if b in dic: dic[b].append(i) else: dic[b]= [i] for k in dic.keys(): dic[k].sort(reverse=True) bit = Bit(N-1) ans = 0 for i,a in enumerate(A2,1): x = dic[a][-1] dic[a].pop(-1) bit.add(x,1) ans += i - bit.sum(x) print(ans)