結果
| 問題 | 
                            No.1115 二つの数列 / Two Sequences
                             | 
                    
| コンテスト | |
| ユーザー | 
                             wolgnik
                         | 
                    
| 提出日時 | 2020-07-17 21:41:08 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 154 ms / 2,000 ms | 
| コード長 | 1,052 bytes | 
| コンパイル時間 | 317 ms | 
| コンパイル使用メモリ | 81,792 KB | 
| 実行使用メモリ | 106,880 KB | 
| 最終ジャッジ日時 | 2024-11-29 22:42:41 | 
| 合計ジャッジ時間 | 5,427 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 35 | 
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
table = [0] * (N + 1)
revtable = [0] * (N + 1)
for i in range(N):
  table[a[i]] = i + 1
  revtable[i + 1] = a[i]
bb = [0] * N
for i in range(N): bb[i] = table[b[i]]
#print(bb)
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[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)
  def lowerbound(self, s):
    x = 0
    y = 0
    for i in range(self.n.bit_length(), -1, -1):
      k = x + (1 << i)
      if k <= self.n and (y + self.data[k] < s):
        y += self.data[k]
        x += 1 << i
    return x + 1
fwk = BIT(N)
res = 0
for x in bb[: : -1]:
  res += fwk.sum(x)
  fwk.add(x, 1)
print(res)
            
            
            
        
            
wolgnik