結果

問題 No.1282 Display Elements
ユーザー AEnAEn
提出日時 2022-11-25 22:56:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 168,228 KB
最終ジャッジ日時 2024-04-10 04:03:30
合計ジャッジ時間 4,290 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,096 KB
testcase_01 AC 36 ms
51,712 KB
testcase_02 AC 36 ms
51,840 KB
testcase_03 AC 38 ms
52,096 KB
testcase_04 AC 36 ms
52,224 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 37 ms
52,096 KB
testcase_07 AC 37 ms
52,224 KB
testcase_08 AC 37 ms
52,096 KB
testcase_09 AC 37 ms
51,968 KB
testcase_10 AC 45 ms
59,904 KB
testcase_11 AC 45 ms
59,776 KB
testcase_12 AC 37 ms
52,352 KB
testcase_13 AC 47 ms
60,032 KB
testcase_14 AC 49 ms
62,336 KB
testcase_15 AC 260 ms
158,888 KB
testcase_16 AC 125 ms
112,012 KB
testcase_17 AC 213 ms
141,340 KB
testcase_18 AC 146 ms
115,744 KB
testcase_19 AC 103 ms
96,128 KB
testcase_20 AC 113 ms
97,580 KB
testcase_21 AC 281 ms
167,884 KB
testcase_22 AC 128 ms
96,424 KB
testcase_23 AC 288 ms
168,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Binary_Indexed_Tree:
    def __init__(self, n) -> None:
        self._n = n
        self.data = [0] * (n+1)
        self.depth = n.bit_length()

    def add(self, p, x) -> None:
        """任意の要素ai←ai+xを行う O(logn)"""
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p-1] += x
            p += p & (-p)
    
    def sum(self, l, r) -> int:
        """区間[l,r)で計算"""
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
    
    def _sum(self, d) -> int:
        sm = 0
        while d > 0:
            sm += self.data[d-1]
            d -= d & (-d)
        return sm

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

x_dic = {num:i for i, num in enumerate(list(sorted(set(a+b))))}
res = 0
BIT = Binary_Indexed_Tree(len(x_dic)+5)
for i in range(N):
    BIT.add(x_dic[b[i]],1)
    res += BIT._sum(x_dic[a[i]])
print(res)
0