Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Feb 14, 2025

🧷 문제 링크

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

🧭 풀이 시간

8분

👀 체감 난이도

✏️ 문제 설명

길이 $N$인 수열 $A$가 주어지면, $\sum \limits_{i=1}^N {\sum \limits_{j=i+1}^N {A_i \oplus A_j}}$를 구해보자.
$\oplus$는 xor을 의미한다.

🔍 풀이 방법

  • 두 수의 xor은 비트 별로 독립적으로 수행해도 된다.
  • 각 비트에 대한 xor을 빠르게 구할 수 있다면, 이를 $O(\log{N})$번 반복해서 전체 문제를 풀 수 있다.
  • xor의 성질에 따라 비트가 켜져있는 수에서 하나를 고르고, 비트가 꺼져있는 수에서 하나를 골라야만 $0$이 아닌 수가 나온다.
  • $N$개의 수 중, $i$번째 비트가 켜져있는 수의 개수를 $C_i$라고 정의하면, $i$번째 비트에 대한 답은 $C_i \times (N - C_i) \times 2^i$이다.
  • 모든 비트에 대해 수행하면 정답을 구할 수 있다.

⏳ 회고

@ShinHeeEul ShinHeeEul merged commit 736ae7c into main Feb 14, 2025
1 check passed
@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Feb 14, 2025
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