結果

問題 No.1282 Display Elements
ユーザー ayaoniayaoni
提出日時 2020-11-06 23:31:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 171,880 KB
最終ジャッジ日時 2023-09-29 19:41:23
合計ジャッジ時間 5,278 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
78,788 KB
testcase_01 AC 96 ms
78,956 KB
testcase_02 AC 96 ms
78,788 KB
testcase_03 AC 94 ms
78,852 KB
testcase_04 AC 96 ms
78,684 KB
testcase_05 AC 94 ms
79,092 KB
testcase_06 AC 94 ms
78,872 KB
testcase_07 AC 97 ms
78,988 KB
testcase_08 AC 97 ms
79,036 KB
testcase_09 AC 97 ms
78,836 KB
testcase_10 AC 102 ms
79,296 KB
testcase_11 AC 100 ms
79,424 KB
testcase_12 AC 98 ms
78,972 KB
testcase_13 AC 98 ms
79,064 KB
testcase_14 AC 103 ms
79,904 KB
testcase_15 AC 314 ms
162,372 KB
testcase_16 AC 185 ms
107,552 KB
testcase_17 AC 282 ms
144,884 KB
testcase_18 AC 201 ms
106,536 KB
testcase_19 AC 164 ms
100,688 KB
testcase_20 AC 174 ms
100,588 KB
testcase_21 AC 347 ms
171,244 KB
testcase_22 AC 189 ms
101,440 KB
testcase_23 AC 345 ms
171,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


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,B = LI(),LI()
A.sort()

# 座標圧縮

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):
    a = A[i]
    b = B[i]
    bit.update(d[b],1)
    ans += bit.query(d[a]-1)

print(ans)
0