Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Oct 16, 2025

🧷 문제 링크

https://www.acmicpc.net/problem/16979

🧭 풀이 시간

80분

👀 체감 난이도

✏️ 문제 설명

길이 N인 수열 A에 아래 쿼리를 수행해보자.

  • s e : s <= i < j <= e이면서 A[i] > A[j]인 (i,j) 쌍의 개수를 출력

🔍 풀이 방법

  • mo's
  • 펜윅 트리

mo's로 쿼리 정렬하고 처리는 아래와 같이 ㄱㄱ

  1. r이 늘어날 때 -> 답에 a[r]보다 큰 수의 개수만큼 +
  2. r이 줄어들 때 -> 답에 a[r]보다 큰 수의 개수만큼 -
  3. l이 늘어날 때 -> 답에 a[l]보다 작은 수의 개수만큼 -
  4. l이 줄어들 때 -> 답에 a[l]보다 작은 수의 개수만큼 +

수열의 값을 압축해서 O(N)범위로 떨군 후에, 특정 수보다 큰/작은 수의 개수를 펜윅 트리로 구했다.

⏳ 회고

세그먼트 트리 -> 시간 초과
펜윅 트리 써야 맞음. 세그로 뚫어보려다 시간만 날림.

@oncsr oncsr self-assigned this Oct 16, 2025
@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Oct 16, 2025
@ShinHeeEul ShinHeeEul merged commit fc5d750 into main Oct 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants