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/1849
🧭 풀이 시간
70 분
👀 체감 난이도
✏️ 문제 설명
1부터 N까지의 수들이 한 번씩 쓰인 수열이 있다. 그 수열에서 i 앞에 있는 수 들 중, i보다 큰 수들의 개수를 A[i]라고 정의하자. A[i]가 주어져 있을 때, 원래 수열을 구하는 프로그램을 작성하여라.
문제 추가 설명
예를 들어
5 0 1 2 1 2 0 0이라는 값은2 7 3 5 4 1 8 6에서 i 앞에 있는 수 중 i보다 큰 수들의 갯수이다.즉
2 7 3 5 4 1 8 6에서 현재 위치의 값보다 앞에 있는 값들 중 나보다 더 큰 값이 몇 개인지를 센 것이 입력으로 주어진다는 것이다.2보다 앞에 있는 것은 없으므로 A[2] = 0
7보다 앞에 있는 값은 2밖에 없으므로 A[7] = 0
3보다 앞에 있는 값들 중 7이 3보다 크므로 A[3] = 1
5보다 앞에 있는 값들 중 7이 5보다 크므로 A[5] = 1
4보다 앞에 있는 값들 중 5, 7이 4보다 크므로 A[4] = 2
....
이렇게 하고 A[1], A[2], A[3], A[4] ... 를 계산하면
5 0 1 2 1 2 0 0이 나온다. 이를 역으로 계산해서2 7 3 5 4 1 8 6을 도출해내는게 문제이다.🔍 풀이 방법
세그먼트 트리의 리프 노드 값을 전부 비워둔다. 위 노드들은 해당 범위에 빈공간이 몇개가 있는 지를 저장한다.
1부터 N까지 순차적으로 값을 집어넣는다. 이때 탑 다운 방식으로 루트 노드부터 내려온다.
⏳ 회고
문제가 말이 너무 어려웠다. 알고리즘 문제가 아니라 암호 해독 하는 줄