結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tcltktcltk
提出日時 2021-02-01 13:19:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 129,408 KB
最終ジャッジ日時 2023-09-12 10:08:36
合計ジャッジ時間 12,374 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
84,960 KB
testcase_01 AC 212 ms
81,544 KB
testcase_02 AC 220 ms
81,524 KB
testcase_03 AC 304 ms
123,972 KB
testcase_04 AC 320 ms
129,128 KB
testcase_05 AC 308 ms
123,800 KB
testcase_06 AC 297 ms
119,136 KB
testcase_07 AC 314 ms
129,144 KB
testcase_08 AC 227 ms
84,620 KB
testcase_09 AC 269 ms
111,840 KB
testcase_10 AC 299 ms
129,356 KB
testcase_11 AC 212 ms
81,532 KB
testcase_12 AC 306 ms
129,356 KB
testcase_13 AC 311 ms
129,408 KB
testcase_14 AC 315 ms
129,404 KB
testcase_15 AC 217 ms
81,504 KB
testcase_16 AC 219 ms
81,444 KB
testcase_17 AC 220 ms
81,432 KB
testcase_18 AC 211 ms
81,484 KB
testcase_19 AC 211 ms
81,516 KB
testcase_20 AC 215 ms
81,548 KB
testcase_21 AC 223 ms
81,316 KB
testcase_22 AC 211 ms
81,448 KB
testcase_23 AC 232 ms
84,700 KB
testcase_24 AC 256 ms
96,744 KB
testcase_25 AC 295 ms
118,952 KB
testcase_26 AC 242 ms
88,580 KB
testcase_27 AC 273 ms
102,604 KB
testcase_28 AC 286 ms
112,012 KB
testcase_29 AC 287 ms
119,188 KB
testcase_30 AC 311 ms
128,732 KB
testcase_31 AC 245 ms
91,344 KB
testcase_32 AC 239 ms
87,548 KB
testcase_33 AC 294 ms
123,936 KB
testcase_34 AC 217 ms
81,552 KB
testcase_35 AC 214 ms
81,428 KB
testcase_36 AC 210 ms
81,296 KB
testcase_37 AC 211 ms
81,524 KB
testcase_38 AC 209 ms
81,416 KB
testcase_39 AC 214 ms
81,280 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()))
    D = dict()
    for i in range(N):
        D[B[i]] = i
    A1 = [D[A[i]] 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