[20250809] BOJ / P4 / 다오의 행사 계획하기 / 권혁준 #639
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/26615
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
N*M 크기의 격자형태 미로가 있다.
격자의 두 칸을 잇는 벽이 있을 수도 있다.
격자 내의 임의의 두 칸을 잇는 경로는 정확히 1개가 되도록 입력이 주어진다.
K개의 이벤트가 열린다.
각 이벤트는 s일부터 e일까지 열리며, 해당 기간에 (a,b)에서 (c,d)를 잇는 경로 상에 사람이 V명 증가한다.
각 날마다 오는 사람의 수를 구해보자.
🔍 풀이 방법
격자로 주어지지만 조건 때문에 모양이 반드시 트리가 된다.
그럼 이벤트는 트리에서 두 점 사이의 거리를 요구하는 문제로 바뀐다.
거리 d를 구해서, 날짜 배열 A의 [s,e]구간에 vd만큼 더해주면 된다.
이건 구간 갱신 쿼리라 시간이 오래 걸리는데, 이벤트가 모두 끝난 후 마지막 한 번만 출력하면 되니까 imos법을 쓸 수 있다.
A[s]에 vd만큼 더하고 A[e+1]에 v*d만큼 뺸 뒤, 답을 구할 때 누적 합으로 구해줬다.
⏳ 회고
신기한 문제