結果
問題 |
No.1209 XOR Into You
|
ユーザー |
|
提出日時 | 2022-12-07 17:13:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,095 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 125,812 KB |
最終ジャッジ日時 | 2024-10-13 22:42:43 |
合計ジャッジ時間 | 9,505 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 9 WA * 28 |
ソースコード
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() X = [] Y = [] for i in range(N-1): X.append(A[i+1] ^ A[i]) Y.append(B[i+1] ^ B[i]) if sorted(X) != sorted(Y): print(-1) exit() Z = {} g = 0 for y in Y: if not y in Z: Z[y] = g g += 1 X = [Z[x] for x in X] G = fenwick_tree(g) ans = 0 for x in X[::-1]: ans += G.sum0(x) G.add(x, 1) print(ans)