[20250210] BOJ / 플래2 / Promotion Counting / 권혁준#71
Merged
ShinHeeEul merged 1 commit intomainfrom Feb 10, 2025
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/14446
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
정점$N$ 개인 트리가 있고, 각 점 $i$ 는 값 $P[i]$ 를 가진다.
각 점$i$ 마다, $i$ 를 루트로 하는 서브트리 내에서 $P[j] > P[i]$ 인 $j$ 의 개수를 구해보자.
🔍 풀이 방법
오일러 경로 테크닉으로 트리를 일자로 편다.
세그먼트 트리와 병합 정렬을 이용해서 일자로 편 트리에 대한 머지 소트 트리를 만든다.
각 점 i의 in, out에 대해, 세그먼트 트리에서 in+1 ~ out 범위에 속하는 노드들 중 P[i]보다 큰 값의 개수를 upper bound로 구해서 더해주면 된다.
⏳ 회고
자바로 구현하니까 upper bound도 직접 짜야하고, 병합하는 merge함수도 없고 여러모로 귀찮은 부분이 많았다.