結果

問題 No.1282 Display Elements
コンテスト
ユーザー chineristAC
提出日時 2020-11-06 22:12:29
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 247 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 156,316 KB
最終ジャッジ日時 2026-04-03 09:09:12
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

N = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
res = 0

S = set([a[i] for i in range(N)]+[b[i] for i in range(N)])
S = list(S)
S.sort()
comp = {i:e+1 for e,i in enumerate(S)}

bit = BIT(len(S))
for i in range(N):
    bit.update(comp[b[i]],1)
    res += bit.query(comp[a[i]]-1)

print(res)
0