結果

問題 No.1282 Display Elements
ユーザー marroncastlemarroncastle
提出日時 2020-11-06 22:23:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 171,916 KB
最終ジャッジ日時 2023-09-29 19:03:46
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,212 KB
testcase_01 AC 73 ms
71,592 KB
testcase_02 AC 73 ms
71,508 KB
testcase_03 AC 73 ms
71,372 KB
testcase_04 AC 74 ms
71,396 KB
testcase_05 AC 72 ms
71,420 KB
testcase_06 AC 73 ms
71,400 KB
testcase_07 AC 73 ms
71,272 KB
testcase_08 AC 71 ms
71,124 KB
testcase_09 AC 71 ms
71,340 KB
testcase_10 AC 80 ms
76,008 KB
testcase_11 AC 79 ms
76,356 KB
testcase_12 AC 71 ms
71,432 KB
testcase_13 AC 77 ms
75,992 KB
testcase_14 AC 80 ms
76,404 KB
testcase_15 AC 300 ms
162,768 KB
testcase_16 AC 162 ms
107,608 KB
testcase_17 AC 252 ms
144,592 KB
testcase_18 AC 181 ms
106,344 KB
testcase_19 AC 144 ms
100,892 KB
testcase_20 AC 153 ms
100,856 KB
testcase_21 AC 325 ms
171,588 KB
testcase_22 AC 167 ms
101,500 KB
testcase_23 AC 320 ms
171,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.bit[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.bit[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i-1)
  def lower_bound(self,x):
    w = i = 0
    k = 1<<((self.n).bit_length())
    while k:
      if i+k <= self.n and w + self.bit[i+k] < x:
        w += self.bit[i+k]
        i += k
      k >>= 1
    return i+1

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
comp = lambda arr: {e: i+1 for i, e in enumerate(sorted(set(arr)))}
compAB = comp(A+B)
bit = BIT(2*N+2)
ans = 0
for i in range(N):
  bit.add(compAB[B[i]],1)
  ans += bit.sum(compAB[A[i]]-1)
print(ans)
0