結果
| 問題 | No.1282 Display Elements | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-02-19 11:08:15 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 355 ms / 2,000 ms | 
| コード長 | 912 bytes | 
| コンパイル時間 | 493 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 182,172 KB | 
| 最終ジャッジ日時 | 2024-09-15 19:52:17 | 
| 合計ジャッジ時間 | 4,267 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
# 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)
            
            
            
        