結果

問題 No.1209 XOR Into You
ユーザー shotoyooshotoyoo
提出日時 2021-05-17 23:42:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,484 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 115,200 KB
最終ジャッジ日時 2024-04-16 11:18:29
合計ジャッジ時間 9,392 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 42 ms
52,736 KB
testcase_02 AC 42 ms
52,480 KB
testcase_03 AC 42 ms
52,864 KB
testcase_04 AC 128 ms
96,896 KB
testcase_05 WA -
testcase_06 AC 128 ms
96,768 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 143 ms
95,872 KB
testcase_22 AC 155 ms
114,176 KB
testcase_23 AC 155 ms
113,664 KB
testcase_24 AC 155 ms
113,536 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 136 ms
98,688 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 155 ms
113,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))

class BIT:
    ### BIT binary
    def __init__(self, n, values=None):
        self.bit = [0]*(n+1)
        self.n = n
        self.total = 0
        if values is not None:
            for i,v in enumerate(values):
                self.add(i,v)
                self.total += v
    def check(self):
        l = []
        prv = 0
        for i in range(1,self.n+1):
            val = self.query(i)
            l.append(val-prv)
            prv = val
        print(" ".join(map(str, l)))
    #a1 ~ aiまでの和 O(logn)
    def query(self,i):
        res = 0
        while i > 0:
            res += self.bit[i]
            # res %= M
            i -= i&(-i)
        return res
    def get(self,i):
        return self.query(i+1) - self.query(i)
    #ai += x(logN)
    def add(self,i,x):
        i += 1
        if i==0:
            raise RuntimeError
        self.total += x
        while i <= self.n:
            self.bit[i] += x
            # self.bit[i] %= M
            i += i&(-i)
    def index(self, v):
        """a0,...,aiの和がv以上になる最小のindexを求める
        存在しないとき配列サイズを返す
        """
        if v <= 0:
            return 0
        if self.total<v:
            return self.n
        x = 0
        r = 1
        while r < self.n:
            r = r << 1;
        ll = r
        while ll>0:
            if x+ll<self.n and self.bit[x+ll]<v:
                v -= self.bit[x+ll]
                x += ll
            ll = ll>>1
        return x
# 転倒数を求める例: 圧縮なし
from bisect import bisect_left
def press(l):
    # xs[inds[i]]==l[i]となる
    xs = sorted(set(l))
    inds = [None] * len(l)
#     d = {}
    for i,item in enumerate(l):
        inds[i] = bisect_left(xs, item)
#         d[item] = inds[i]
    return xs, inds

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [a[i]^a[i+1] for i in range(n-1)]
bb = [b[i]^b[i+1] for i in range(n-1)]
if sorted(aa)!=sorted(bb):
    ans = -1
else:
    index = {}
    for i in range(n-1):
        index[bb[i]] = i    
    bit = BIT(n-1)
    na = [index[aa[i]] for i in range(n-1)]
    ans = 0
    for i in range(n-1):
        ans += i - bit.query(na[i]+1)
        bit.add(na[i], 1)
print(ans)
0