結果

問題 No.1282 Display Elements
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-11-06 22:32:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 170,004 KB
最終ジャッジ日時 2023-09-29 19:12:45
合計ジャッジ時間 5,547 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,080 KB
testcase_01 AC 72 ms
70,908 KB
testcase_02 AC 71 ms
71,112 KB
testcase_03 AC 71 ms
71,120 KB
testcase_04 AC 73 ms
71,148 KB
testcase_05 AC 71 ms
70,760 KB
testcase_06 AC 72 ms
71,148 KB
testcase_07 AC 70 ms
70,944 KB
testcase_08 AC 70 ms
70,976 KB
testcase_09 AC 71 ms
71,016 KB
testcase_10 AC 78 ms
75,572 KB
testcase_11 AC 75 ms
75,868 KB
testcase_12 AC 72 ms
71,104 KB
testcase_13 AC 78 ms
75,252 KB
testcase_14 AC 79 ms
76,048 KB
testcase_15 AC 307 ms
160,388 KB
testcase_16 AC 159 ms
108,320 KB
testcase_17 AC 253 ms
142,868 KB
testcase_18 AC 179 ms
105,864 KB
testcase_19 AC 132 ms
97,088 KB
testcase_20 AC 141 ms
97,156 KB
testcase_21 AC 326 ms
169,908 KB
testcase_22 AC 160 ms
98,288 KB
testcase_23 AC 329 ms
170,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N, = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(set(X+Y))
Z.sort()
x2i = dict()
i = 1
for z in Z:
    x2i[z] = i
    i+=1
M = i
bt = Bit(M)
X.sort()
R = 0
for i in range(N):
    y = x2i[Y[i]]
    bt.add(y, 1)
    x = x2i[X[i]]
    R += bt.sum(x-1)
print(R)

0