結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-02 19:20:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,432 ms / 2,000 ms |
| コード長 | 821 bytes |
| コンパイル時間 | 351 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 33,720 KB |
| 最終ジャッジ日時 | 2024-10-12 09:21:16 |
| 合計ジャッジ時間 | 17,122 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
class Bit:
"""1-indexed"""
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 sum(self, i, j):
"""閉区間[i, j]"""
return self._sum(j) - self._sum(i - 1)
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
N, M = map(int, input().split())
B = Bit(M)
queries = []
for i in range(N):
a, b = sorted([int(x) + 1 for x in input().split()])
queries.append((a, 1))
queries.append((b, 2, a))
queries.sort()
ans = 0
for q in queries:
if q[1] == 1:
B.add(q[0], 1)
elif q[1] == 2:
B.add(q[2], -1)
ans += B.sum(q[2], q[0])
print(ans)