ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 24320 |
문제명 | Rectpoints |
레벨 | 플래티넘 2 |
분류 |
스위핑, 세그먼트트리 |
시간복잡도 | O(nlogn) |
인풋사이즈 | n<=10^5 |
사용한 언어 | PyPy |
제출기록 | 213684KB / 2228ms |
최고기록 | 2228ms |
해결날짜 | 2023/08/30 |
"""Solution code for "BOJ 24320. Rectpoints".
- Problem link: https://www.acmicpc.net/problem/24320
- Solution link: http://www.teferi.net/ps/problems/boj/24320
Tags: [lazy segtree]
"""
import sys
from teflib import segmenttree
ADD = 0
REMOVE = 1
def main():
N, w, h = [int(x) for x in sys.stdin.readline().split()]
events = []
y_coords = set()
for _ in range(N):
x, y = [int(x) for x in sys.stdin.readline().split()]
y_coords.add(y)
y_coords.add(y + h + 1)
events.append((x, ADD, y))
events.append((x + w, REMOVE, y))
size = len(y_coords)
compress_map = {y: i for i, y in enumerate(sorted(y_coords))}
segtree = segmenttree.LazySegmentTree(
[0] * size,
merge=max,
update_value=lambda v, p, _: v + p,
update_param=lambda p1, p2: p1 + p2,
)
answer = 0
for _, type_, y in sorted(events):
beg, end = compress_map[y], compress_map[y + h + 1]
if type_ == ADD:
segtree.range_update(beg, end, 1)
answer = max(answer, segtree.query(0, size))
elif type_ == REMOVE:
segtree.range_update(beg, end, -1)
print(answer)
if __name__ == '__main__':
main()