結果

問題 No.1282 Display Elements
ユーザー Coki628Coki628
提出日時 2020-12-08 18:15:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 2,057 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 202,408 KB
最終ジャッジ日時 2023-10-17 18:39:09
合計ジャッジ時間 4,803 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,804 KB
testcase_01 AC 38 ms
53,804 KB
testcase_02 AC 37 ms
53,804 KB
testcase_03 AC 38 ms
53,804 KB
testcase_04 AC 37 ms
53,804 KB
testcase_05 AC 37 ms
53,804 KB
testcase_06 AC 38 ms
53,804 KB
testcase_07 AC 38 ms
53,804 KB
testcase_08 AC 38 ms
53,804 KB
testcase_09 AC 38 ms
53,804 KB
testcase_10 AC 45 ms
62,184 KB
testcase_11 AC 45 ms
62,184 KB
testcase_12 AC 39 ms
53,828 KB
testcase_13 AC 46 ms
61,712 KB
testcase_14 AC 51 ms
64,480 KB
testcase_15 AC 331 ms
189,372 KB
testcase_16 AC 148 ms
106,832 KB
testcase_17 AC 275 ms
166,940 KB
testcase_18 AC 173 ms
114,000 KB
testcase_19 AC 102 ms
97,256 KB
testcase_20 AC 117 ms
97,728 KB
testcase_21 AC 354 ms
202,144 KB
testcase_22 AC 135 ms
97,952 KB
testcase_23 AC 356 ms
202,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        self.n = n
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加:添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def query(self, l, r):
        """ 区間和の取得 [l, r) """
        return self.sum(r-1) - self.sum(l-1)
    
    def get(self, i):
        """ 一点取得 """
        return self.query(i, i+1)

    def update(self, i, x):
        """ 値の更新:添字i, 値x """
        self.add(i, x - self.get(i))

    def print(self):
        for i in range(self.n):
            print(self.get(i), end=' ')
        print()

def compress(S):
    """ 座標圧縮 """

    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(S)):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

N = INT()
A = LIST()
B = LIST()

A.sort()
zp, unzp = compress(set(A+B))
M = len(zp)
bit = BIT(M)
ans = 0
for i in range(N):
    bit.add(zp[B[i]], 1)
    ans += bit.query(0, zp[A[i]])
print(ans)
0