結果

問題 No.1282 Display Elements
ユーザー rin204
提出日時 2022-07-08 09:11:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 180,860 KB
最終ジャッジ日時 2024-12-26 06:34:27
合計ジャッジ時間 4,768 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.n0 = 1 << (n.bit_length() - 1)
        self.tree = [0] * (n + 1)
    
    def range_sum(self, l, r):
        return self.sum(r - 1) - self.sum(l - 1)
        
    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
        
    def get(self, i):
        return self.sum(i) - self.sum(i - 1)
 
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
         
    def lower_bound(self, x):
        pos = 0
        plus = self.n0
        while plus > 0:
            if pos + plus <= self.size and self.tree[pos + plus] < x:
                x -= self.tree[pos + plus]
                pos += plus
            plus //= 2
        return pos



n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
se = set(A) | set(B)
dic = {s:i for i, s in enumerate(sorted(se))}
le = len(se)
bit = Bit(le)
A.sort()
ans = 0
for a, b in zip(A, B):
    a = dic[a]
    b = dic[b]
    bit.add(b, 1)
    ans += bit.sum(a - 1)
print(ans)
0