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/12844
🧭 풀이 시간
60 분
👀 체감 난이도
✏️ 문제 설명
크기가 N인 수열 A0, A1, ..., AN-1이 주어졌을 때, 다음 두 종류의 쿼리를 수행해보자.
1 i j k: Ai, Ai+1, ..., Aj에 k를 xor한다.
2 i j: Ai, Ai+1, ..., Aj를 모두 xor한 다음 출력한다.
🔍 풀이 방법
느리게 갱신되는 세그먼트 트리에 XOR로 더해가는 방식이다. XOR 특성 상 짝수 번 XOR 되면 안 한 것과 같다. 그러므로 updateLazy 함수에서 현재 범위를 업데이트해야 한다 하면, 범위가 홀수인지 체크하고, 홀수라면 업데이트한다. 그리고 홀수 여부를 부모 updateLazy 함수에게 반환해준다.
반환 받은 부모 updateLazy 함수에서 자식들의 반환값을 XOR하고(만약 둘 다 True를 반환한다면 현재 위치에서는 짝수번 업데이트 된다는 것으로 업데이트 할 필요가 없다!) True인 경우 다시 현재 노드에 업데이트, 아니라면 False를 그 부모에게 전달한다.
⏳ 회고
좀 성장한듯 ㅎ