結果

問題 No.1282 Display Elements
ユーザー chineristACchineristAC
提出日時 2020-11-06 22:12:29
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 171,656 KB
最終ジャッジ日時 2023-09-29 18:53:54
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,324 KB
testcase_01 AC 65 ms
70,932 KB
testcase_02 AC 63 ms
71,420 KB
testcase_03 AC 64 ms
71,320 KB
testcase_04 AC 65 ms
71,324 KB
testcase_05 AC 65 ms
71,312 KB
testcase_06 AC 63 ms
71,328 KB
testcase_07 AC 63 ms
70,932 KB
testcase_08 AC 66 ms
71,296 KB
testcase_09 AC 66 ms
71,144 KB
testcase_10 AC 74 ms
76,120 KB
testcase_11 AC 69 ms
76,196 KB
testcase_12 AC 70 ms
71,264 KB
testcase_13 AC 78 ms
75,652 KB
testcase_14 AC 74 ms
76,156 KB
testcase_15 AC 265 ms
162,208 KB
testcase_16 AC 143 ms
100,012 KB
testcase_17 AC 230 ms
144,056 KB
testcase_18 AC 165 ms
106,888 KB
testcase_19 AC 124 ms
98,968 KB
testcase_20 AC 134 ms
99,160 KB
testcase_21 AC 287 ms
171,584 KB
testcase_22 AC 151 ms
99,892 KB
testcase_23 AC 277 ms
171,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

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

S = set([a[i] for i in range(N)]+[b[i] for i in range(N)])
S = list(S)
S.sort()
comp = {i:e+1 for e,i in enumerate(S)}

bit = BIT(len(S))
for i in range(N):
    bit.update(comp[b[i]],1)
    res += bit.query(comp[a[i]]-1)

print(res)
0