結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tcltktcltk
提出日時 2021-02-01 13:17:39
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,529 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 116,080 KB
最終ジャッジ日時 2023-09-12 10:08:10
合計ジャッジ時間 13,539 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 227 ms
84,428 KB
testcase_01 AC 207 ms
81,252 KB
testcase_02 AC 207 ms
81,248 KB
testcase_03 AC 284 ms
111,500 KB
testcase_04 AC 289 ms
115,612 KB
testcase_05 AC 275 ms
111,584 KB
testcase_06 AC 270 ms
108,272 KB
testcase_07 AC 286 ms
115,688 KB
testcase_08 AC 221 ms
84,328 KB
testcase_09 AC 257 ms
103,036 KB
testcase_10 AC 280 ms
116,012 KB
testcase_11 AC 204 ms
81,428 KB
testcase_12 AC 286 ms
116,064 KB
testcase_13 AC 287 ms
115,924 KB
testcase_14 AC 286 ms
116,080 KB
testcase_15 AC 204 ms
81,172 KB
testcase_16 AC 203 ms
81,424 KB
testcase_17 AC 203 ms
81,176 KB
testcase_18 AC 208 ms
81,300 KB
testcase_19 AC 204 ms
81,440 KB
testcase_20 AC 202 ms
81,476 KB
testcase_21 AC 204 ms
81,300 KB
testcase_22 AC 202 ms
81,500 KB
testcase_23 AC 227 ms
84,448 KB
testcase_24 AC 238 ms
93,020 KB
testcase_25 AC 269 ms
107,632 KB
testcase_26 AC 231 ms
86,544 KB
testcase_27 AC 249 ms
96,524 KB
testcase_28 AC 265 ms
103,360 KB
testcase_29 AC 275 ms
108,232 KB
testcase_30 AC 289 ms
115,600 KB
testcase_31 AC 237 ms
88,776 KB
testcase_32 AC 230 ms
86,004 KB
testcase_33 AC 275 ms
111,824 KB
testcase_34 AC 204 ms
81,280 KB
testcase_35 AC 201 ms
81,392 KB
testcase_36 AC 203 ms
81,396 KB
testcase_37 AC 203 ms
81,500 KB
testcase_38 AC 205 ms
81,512 KB
testcase_39 AC 203 ms
81,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

# 最もシンプル
class BIT:
    """
    Binary Indexed Tree (Fenwick Tree), 1-indexed
    """

    def __init__(self, n):
        """
        Parameters
        ----------
        n : int
            要素数。index は 0..n になる。
        """
        self.size = n
        self.data = [0] * (n+1)
        # self.depth = n.bit_length()

    def add(self, i, x):
        while i <= self.size:
            self.data[i] += x
            i += i & -i

    def get_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def get_rsum(self, l, r):
        """
        [l, r) の sum
        """
        return self.get_sum(r) - self.get_sum(l-1)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    T = [None for _ in range(N)]
    for i in range(N):
        T[B[i]-1] = i
    A1 = [T[A[i]-1] for i in range(N)]

    bit = BIT(N)
    v = 0
    for a in reversed(A1):
        v += bit.get_sum(a+1)
        bit.add(a+1, 1)
    print(v)

if __name__ == '__main__':
    main()
0