結果

問題 No.1282 Display Elements
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-19 11:08:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 186,228 KB
最終ジャッジ日時 2023-10-13 23:59:21
合計ジャッジ時間 5,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,456 KB
testcase_01 AC 75 ms
71,232 KB
testcase_02 AC 76 ms
71,308 KB
testcase_03 AC 76 ms
71,472 KB
testcase_04 AC 76 ms
71,156 KB
testcase_05 AC 76 ms
71,348 KB
testcase_06 AC 77 ms
71,380 KB
testcase_07 AC 75 ms
71,476 KB
testcase_08 AC 76 ms
71,336 KB
testcase_09 AC 77 ms
71,128 KB
testcase_10 AC 79 ms
75,632 KB
testcase_11 AC 79 ms
75,668 KB
testcase_12 AC 74 ms
71,484 KB
testcase_13 AC 84 ms
75,820 KB
testcase_14 AC 82 ms
76,288 KB
testcase_15 AC 349 ms
176,780 KB
testcase_16 AC 177 ms
102,964 KB
testcase_17 AC 296 ms
156,004 KB
testcase_18 AC 201 ms
113,332 KB
testcase_19 AC 136 ms
95,336 KB
testcase_20 AC 147 ms
95,360 KB
testcase_21 AC 371 ms
186,208 KB
testcase_22 AC 162 ms
96,096 KB
testcase_23 AC 371 ms
186,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 0-indexed binary indexed tree
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0]*(n+1)
    self.el = [0]*(n+1)
  # sum of [0,i) sum(a[:i])
  def sum(self, i):
    if i==0:return 0
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    i+=1
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  # sum of [l,r)   sum(a[l:r])
  def sumlr(self, i, j):
    return self.sum(j) - self.sum(i)
  # a[i]
  def get(self,i):
    i+=1
    return self.el[i]


def main(n,a,b):
  d=set(a)|set(b)
  d=list(d)
  d.sort()
  d={x:i for i,x in enumerate(d)}
  a.sort()
  bit=BIT(len(d))
  ans=0
  for bi,ai in zip(b,a):
    bit.add(d[bi],1)
    ans+=bit.sum(d[ai])
  return ans

if __name__=='__main__':
  n=int(input())
  a=list(map(int,input().split()))
  b=list(map(int,input().split()))
  ret=main(n,a,b)
  print(ret)

0