結果
問題 | No.1282 Display Elements |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2020-11-07 21:47:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 319 ms / 2,000 ms |
コード長 | 1,424 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 86,880 KB |
実行使用メモリ | 181,212 KB |
最終ジャッジ日時 | 2023-09-29 20:54:36 |
合計ジャッジ時間 | 5,217 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
71,052 KB |
testcase_01 | AC | 71 ms
70,808 KB |
testcase_02 | AC | 71 ms
71,080 KB |
testcase_03 | AC | 70 ms
70,784 KB |
testcase_04 | AC | 70 ms
70,640 KB |
testcase_05 | AC | 70 ms
70,932 KB |
testcase_06 | AC | 71 ms
70,876 KB |
testcase_07 | AC | 71 ms
71,124 KB |
testcase_08 | AC | 71 ms
70,988 KB |
testcase_09 | AC | 71 ms
70,920 KB |
testcase_10 | AC | 92 ms
75,808 KB |
testcase_11 | AC | 78 ms
75,712 KB |
testcase_12 | AC | 71 ms
71,032 KB |
testcase_13 | AC | 79 ms
75,816 KB |
testcase_14 | AC | 85 ms
76,160 KB |
testcase_15 | AC | 309 ms
171,956 KB |
testcase_16 | AC | 161 ms
98,900 KB |
testcase_17 | AC | 259 ms
151,244 KB |
testcase_18 | AC | 185 ms
105,612 KB |
testcase_19 | AC | 159 ms
107,532 KB |
testcase_20 | AC | 158 ms
107,468 KB |
testcase_21 | AC | 317 ms
181,212 KB |
testcase_22 | AC | 176 ms
108,116 KB |
testcase_23 | AC | 319 ms
181,024 KB |
ソースコード
class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def build(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] def sum(self, i): # [0, i) の要素の総和を返す s = 0 while i>0: s += self.tree[i] i -= i & -i return s # 0 index を 1 index に変更 転倒数を求めるなら1を足していく def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i # 総和がx以上になる位置のindex をbinary search def bsearch(self,x): le = 0 ri = 1<<(self.size.bit_length()-1) while ri > 0: if le+ri <= self.size and self.tree[le+ri]<x: x -= self.tree[le+ri] le += ri ri >>= 1 return le+1 n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) s = set() for i,j in zip(a,b): s.add(i) s.add(j) l = sorted(list(s)) dic = {} for i,j in enumerate(l,1): dic[j] = i sa = [] sb = [] for i in a: sa.append(dic[i]) for i in b: sb.append(dic[i]) sa.sort() bit = BIT(len(l)+5) ans = 0 for i,j in zip(sb,sa): bit.add(i,1) ans += bit.sum(j) print(ans)