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/12895
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
특정 구간의 집들의 색들을 새롭게 칠하거나, 특정 구간의 집들에 존재하는 색의 수를 알고 싶어졌다.
작업은 다음과 같은 두가지로 이루어 진다.
“C x y z” : x번과 y번, 그리고 그 사이에 있는 모든 집을 z번 색으로 색칠한다.
“Q x y” : x번과 y번, 그리고 그 사이에 있는 모든 집에 존재하는 색의 가짓수를 출력한다.
민호가 사용할 색의 종류는 (1번, 2번, … T번) 이라 하고 처음 모든 집은 1번으로 색칠되어 있다고 생각한다.
작업이 “Q x y”일 때의 경우 x번과 y번, 그리고 그 사이에 있는 모든 집에 존재하는 색의 가짓수를 출력한다.
🔍 풀이 방법
레이지 세그먼트 트리를 연습하기 위해서 푼 문제이기에 당연히 그것부터 도입했다. 그렇게 천천히 도입해서 1시반 30정도 걸렸을 때 풀긴 풀었는데, 시간 초과가 간신히 안된 상태였다.
그렇기에 다른 사람들의 코드를 보니 현재 노드에서 몇가지 색상을 가지고 있냐를 Set이 아니라 비트마스킹으로 표현하고 있었다.
이를 도입하니 정상적인 풀이 시간이 나와 해결하였다.
⏳ 회고
입력값의 제한을 잘 보자. 색상의 제한이 30이길래 왜그런가 했는데 int로 비트마스킹 하라는 뜻이었다..