結果

問題 No.3313 Matryoshka
コンテスト
ユーザー amesyu
提出日時 2025-11-18 22:28:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 779 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 92,720 KB
最終ジャッジ日時 2025-11-18 22:28:29
合計ジャッジ時間 19,386 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

n = int(input())
lim = 10 ** 6
query = [-1] * lim
for _ in range(n):
    li, ri = map(int, input().split())
    query[ri-1] = li-1
ans = 0
bit = Fenwick_Tree(lim)
for i in range(lim):
    if query[i] == -1: continue
    ans += bit.sum(query[i], i)
    bit.add(query[i], 1)
print(ans)
0