QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#10958. All Pairs Similarity

Statistics

Note: The memory limit for this problem is 512MB, twice the default. Farmer John's $N$ ($1\le N\le 5\cdot 10^5$) cows are each assigned a bitstring of length $K$ that is not all zero ($1\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 $\texttt{11001}$ and $\texttt{11010}$ would be $2/4$.

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

Input Format

The first line contains $N$ and $K$. The next $N$ lines each contain an integer $i\in (0,2^K)$, representing a cow associated with the length-$K$ binary representation of $i$.

Output Format

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

Sample Data

Sample Input

4 2
1
1
2
3

Sample Output

500000006
500000006
500000005
500000006

Sample Explanation

The cows are associated with the following bitstrings: $[\texttt{01}, \texttt{01}, \texttt{10}, \texttt{11}]$. For the first cow, the sum is $\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 $\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}$.

For the first cow, the sum is $\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}$. For the third cow, the sum is $\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}$.

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 $\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}$.

For the third cow, the sum is $\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}$.

Constraints

Inputs 2-15: There will be two test cases for each of $K\in \{10,15,16,17,18,19,20\}$.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.