[20250624] BOJ / P5 / 집합 연산 / 권혁준 #384
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/32965
🧭 풀이 시간
80분
👀 체감 난이도
✏️ 문제 설명
N개의 원소로 이루어진 중복을 허용하지 않는 집합 S가 주어진다.
이 집합 S에 아래 연산을 여러 번 할 수 있다.
여기에 연산을 K번 한 결과를 구해보자. (쿼리 형식으로 주어짐)
🔍 풀이 방법
직접 연산을 시뮬레이션해보면, 원소가 범위 형태로 추가/제거 작업이 반복되는 것을 볼 수 있다.
이 범위의 개수는 최대 2N개이다.
범위를 구할 때는 투 포인터로 N을 기준 잡은 뒤, 양쪽으로 뻗어나가면 된다.
⏳ 회고
생각한 풀이는 투 포인터인데, 이걸 구현하려니까 머리가 너무 아프고 시간을 거의 한시간 썼는데도 구현을 못했음
그래서 위 방식대로 동작하도록 TreeSet을 사용함