All Pairs Similarity

시간 제한2초메모리 제한2048 MB

요약
길이 K인 N개의 비트열 각각에 대해 모든 비트열과의 Jaccard 유사도 합을 구해 1e9+7로 나눈 값을 출력한다.
난이도

어려움10점 중 8점

유형
수학, 조합론, 동적 계획법, 비트 연산
정답자
아직 제출이 없습니다

문제

Farmer John's NN (1≤N≤5⋅1051\le N\le 5\cdot 10^5) cows are each assigned a bitstring of length KK that is not all zero (1≤K≤201\le K\le 20). Different cows may be assigned the same bitstring.

The Jaccard similarity of two bitstrings is defined as the number of set bits in their bitwise intersection divided by the number of set bits in their bitwise union. For example, the Jaccard similarity of the bitstrings 11001 and 11010 would be 2/42/4.

For each cow, output the sum of her bitstring's Jaccard similarity with each of the NN cows' bitstrings including her own, modulo 109+710^9+7. Specifically, if the sum is equal to a rational number a/ba/b where aa and bb are integers sharing no common factors, output the unique integer xx in the range \[0,109+7)\[0,10^9+7) such that bx−abx-a is divisible by 109+710^9+7.

입력

The first line contains NN and KK.

The next NN lines each contain an integer i∈(0,2K)i\in (0,2^K), representing a cow associated with the length-KK binary representation of ii.

출력

Output the sum modulo 109+710^9+7 for each cow on a separate line.

힌트

The cows are associated with the following bitstrings: \[\[01, 01, 10, 11]].

For the first cow, the sum is sim(1,1)+sim(1,1)+sim(1,2)+sim(1,3)=1+1+0+1/2≡500000006(mod109+7)\text{sim}(1,1)+\text{sim}(1,1)+\text{sim}(1,2)+\text{sim}(1,3)=1+1+0+1/2\equiv 500000006\pmod{10^9+7}.

The second cow's bitstring is the same as the first cow's, so her sum is the same as above.

For the third cow, the sum is

sim(2,1)+sim(2,1)+sim(2,2)+sim(2,3)=0+0+1+1/2≡500000005(mod109+7)\text{sim}(2,1)+\text{sim}(2,1)+\text{sim}(2,2)+\text{sim}(2,3)=0+0+1+1/2\equiv 500000005\pmod{10^9+7}.

예제1

  1. 예제 1

    입력
    4 2
    1
    1
    2
    3
    
    예상 출력
    500000006
    500000006
    500000005
    500000006