結果

問題 No.1282 Display Elements
ユーザー ayaoniayaoni
提出日時 2020-11-06 21:58:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,342 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 168,704 KB
最終ジャッジ日時 2024-07-22 12:47:05
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class BIT:
    def __init__(self,init_value):
        self.n = len(init_value)
        self.tree = [0]*(self.n+1)
        for i in range(1,self.n+1):
            x = init_value[i-1]
            while i <= self.n:
                self.tree[i] += x
                i += i & (-i)

    def update(self,i,x):  # i(1-index)番目の値を+x
        while i <= self.n:
            self.tree[i] += x
            i += i & (-i)
        return

    def query(self,i):  # 1番目からi(1-index)番目までの和を返す
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & (-i)
        return res


N = I()
A = LI()
A.sort()
B = LI()
X = list(set(A+B))
X.sort()
M = len(X)

d = {}
for i in range(1,M+1):
    d[X[i-1]] = i

bit = BIT([0]*200001)
ans = 0
for i in range(N):
    b = B[i]
    bit.update(d[b],1)
    a = A[i]
    ans += bit.query(d[a]-1)

print(ans)
0