結果

問題 No.1282 Display Elements
ユーザー c-yanc-yan
提出日時 2020-11-07 15:11:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 44,620 KB
最終ジャッジ日時 2023-09-29 20:34:42
合計ジャッジ時間 4,800 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,720 KB
testcase_01 AC 15 ms
7,932 KB
testcase_02 AC 15 ms
7,832 KB
testcase_03 AC 15 ms
7,808 KB
testcase_04 AC 16 ms
7,720 KB
testcase_05 AC 16 ms
7,832 KB
testcase_06 AC 15 ms
7,864 KB
testcase_07 AC 15 ms
7,816 KB
testcase_08 AC 15 ms
7,824 KB
testcase_09 AC 15 ms
7,784 KB
testcase_10 AC 16 ms
8,308 KB
testcase_11 AC 16 ms
8,200 KB
testcase_12 AC 16 ms
7,944 KB
testcase_13 AC 16 ms
8,392 KB
testcase_14 AC 17 ms
8,540 KB
testcase_15 AC 539 ms
43,128 KB
testcase_16 AC 195 ms
19,004 KB
testcase_17 AC 429 ms
30,388 KB
testcase_18 AC 268 ms
25,760 KB
testcase_19 AC 153 ms
23,304 KB
testcase_20 AC 175 ms
23,356 KB
testcase_21 AC 588 ms
44,080 KB
testcase_22 AC 239 ms
23,260 KB
testcase_23 AC 599 ms
44,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def query(bit, start, stop):
    if start == 0:
        return bit_sum(bit, stop - 1)
    else:
        return bit_sum(bit, stop - 1) - bit_sum(bit, start - 1)


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

t = {j: i for i, j in enumerate(sorted(set(a + b)))}
bit = [0] * len(t)

a.sort()
result = 0
for i in range(N):
    bit_add(bit, t[b[i]], 1)
    result += query(bit, 0, t[a[i]])
print(result)
0