結果

問題 No.1282 Display Elements
ユーザー roarisroaris
提出日時 2020-11-14 02:39:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 153,316 KB
最終ジャッジ日時 2023-09-30 04:42:20
合計ジャッジ時間 4,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,620 KB
testcase_01 AC 75 ms
71,232 KB
testcase_02 AC 82 ms
71,528 KB
testcase_03 AC 79 ms
71,588 KB
testcase_04 AC 76 ms
71,396 KB
testcase_05 AC 75 ms
71,708 KB
testcase_06 AC 81 ms
71,632 KB
testcase_07 AC 76 ms
71,664 KB
testcase_08 AC 76 ms
71,540 KB
testcase_09 AC 76 ms
71,472 KB
testcase_10 AC 85 ms
77,088 KB
testcase_11 AC 83 ms
77,240 KB
testcase_12 AC 79 ms
71,636 KB
testcase_13 AC 84 ms
76,352 KB
testcase_14 AC 87 ms
77,180 KB
testcase_15 AC 258 ms
149,780 KB
testcase_16 AC 154 ms
112,404 KB
testcase_17 AC 230 ms
153,316 KB
testcase_18 AC 174 ms
123,032 KB
testcase_19 AC 138 ms
110,056 KB
testcase_20 AC 147 ms
109,436 KB
testcase_21 AC 269 ms
143,572 KB
testcase_22 AC 162 ms
110,732 KB
testcase_23 AC 281 ms
143,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def compress(l):
    l = list(set(l))
    l.sort()
    idx = defaultdict(int)

    for i in range(len(l)):
        idx[l[i]] = i
    
    return idx

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

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

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
idx = compress(a+b)
ans = 0
bit = BIT(2*N)

for ai, bi in zip(a, b):
    bit.add(idx[bi], 1)
    ans += bit.acc(idx[ai])

print(ans)
0