結果

問題 No.1282 Display Elements
ユーザー H3PO4H3PO4
提出日時 2022-02-19 09:54:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 625 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 44,332 KB
最終ジャッジ日時 2023-09-11 20:30:53
合計ジャッジ時間 5,879 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,804 KB
testcase_01 AC 16 ms
7,852 KB
testcase_02 AC 16 ms
7,820 KB
testcase_03 AC 16 ms
7,804 KB
testcase_04 AC 15 ms
7,816 KB
testcase_05 AC 16 ms
7,836 KB
testcase_06 AC 16 ms
7,924 KB
testcase_07 AC 16 ms
7,924 KB
testcase_08 AC 16 ms
7,808 KB
testcase_09 AC 16 ms
7,836 KB
testcase_10 AC 17 ms
8,380 KB
testcase_11 AC 17 ms
8,240 KB
testcase_12 AC 16 ms
7,840 KB
testcase_13 AC 17 ms
8,428 KB
testcase_14 AC 18 ms
8,508 KB
testcase_15 AC 564 ms
43,124 KB
testcase_16 AC 198 ms
18,992 KB
testcase_17 AC 446 ms
30,308 KB
testcase_18 AC 267 ms
25,720 KB
testcase_19 AC 137 ms
22,460 KB
testcase_20 AC 156 ms
22,156 KB
testcase_21 AC 625 ms
44,332 KB
testcase_22 AC 231 ms
22,204 KB
testcase_23 AC 619 ms
44,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline


class Bit:
    """1-indexed"""

    __slots__ = ("size", "tree")

    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 = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))

coor_comp = {x: i for i, x in enumerate(sorted(set(A + B)), 1)}
L = len(coor_comp)
bit = Bit(L)
ans = 0
for a, b in zip(A, B):
    bit.add(coor_comp[b], 1)
    ans += bit.sum(coor_comp[a] - 1)
print(ans)
0