結果
| 問題 | No.1282 Display Elements | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-02-19 09:54:18 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 755 ms / 2,000 ms | 
| コード長 | 734 bytes | 
| コンパイル時間 | 91 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 46,984 KB | 
| 最終ジャッジ日時 | 2024-06-29 10:15:04 | 
| 合計ジャッジ時間 | 6,341 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
import sys
input = sys.stdin.buffer.readline
class Bit:
    """1-indexed"""
    __slots__ = ("size", "tree")
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
coor_comp = {x: i for i, x in enumerate(sorted(set(A + B)), 1)}
L = len(coor_comp)
bit = Bit(L)
ans = 0
for a, b in zip(A, B):
    bit.add(coor_comp[b], 1)
    ans += bit.sum(coor_comp[a] - 1)
print(ans)
            
            
            
        