結果
問題 | No.743 Segments on a Polygon |
ユーザー | rlangevin |
提出日時 | 2024-02-01 12:16:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 491 ms / 2,000 ms |
コード長 | 849 bytes |
コンパイル時間 | 2,376 ms |
コンパイル使用メモリ | 81,444 KB |
実行使用メモリ | 85,984 KB |
最終ジャッジ日時 | 2024-02-01 12:16:24 |
合計ジャッジ時間 | 8,727 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 480 ms
85,984 KB |
testcase_01 | AC | 460 ms
85,600 KB |
testcase_02 | AC | 491 ms
85,600 KB |
testcase_03 | AC | 450 ms
85,600 KB |
testcase_04 | AC | 458 ms
85,604 KB |
testcase_05 | AC | 486 ms
85,596 KB |
testcase_06 | AC | 455 ms
85,600 KB |
testcase_07 | AC | 489 ms
85,600 KB |
testcase_08 | AC | 481 ms
85,604 KB |
testcase_09 | AC | 190 ms
85,712 KB |
ソースコード
import sys input = sys.stdin.readline 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, M = map(int, input().split()) D = [] T = Fenwick_Tree(2 * M + 1) for i in range(N): a, b = map(int, input().split()) if a > b: a, b = b, a T.add(a, 1) T.add(b, -1) D.append((a, b)) D.sort() ans = 0 for a, b in D: ans += T.sum(a, b + 1) T.add(b, 1) print(ans)