[R6F]异或问题 - 代码源竞赛平台

时空限制

2S/512M

题目描述

给定整数 XX 和一个长度为 nn 的整数数组 AA,对于 1∼n1\sim n 的每个 ii 求有多少个 jj 同时满足以下三个条件:

  • i≤ji\leq j;

  • Ai⊕Aj>XA_i\oplus A_j> X;

  • popcount(Ai)≤popcount(Aj)\text{popcount}(A_i)\leq \text{popcount}(A_j)。

这里的 ⊕\oplus 表示按位异或运算。

popcount(V)\text{popcount}(V) 表示求 VV 在二进制下 11 的数量,例如:popcount(7)=3\text{popcount}(7)=3,popcount(16)=1\text{popcount}(16)=1,popcount(0)=0\text{popcount}(0)=0。

格式

输入格式

第一行包含两个整数 nn 和 XX,分别表示数组 AA 的长度和 Ai⊕AjA_i\oplus A_j 需要大于的值。

第二行包含 nn 个整数 AiA_i。

输出格式

输出一行包含 nn 个整数,第 ii 个整数表示有多少个 jj 同时满足三个条件。

样例

样例输入 #1

6 4
3 4 7 6 8 3

样例输出 #1

1 2 0 1 1 0

样例解释 #1

对于 i=1i=1,popcount(A1)=2\text{popcount}(A_1)=2,有一个 jj 满足条件:A1⊕A4=5A_1\oplus A_4=5 且 popcount(A4)=2\text{popcount}(A_4)=2。

对于 i=2i=2,popcount(A2)=1\text{popcount}(A_2)=1,有两个 jj 满足条件:A2⊕A5=12A_2\oplus A_5=12 且 popcount(A5)=1\text{popcount}(A_5)=1,A2⊕A6=7A_2\oplus A_6=7 且 popcount(A6)=2\text{popcount}(A_6)=2。

对于 i=3i=3,popcount(A3)=3\text{popcount}(A_3)=3,有零个 jj 满足条件。

对于 i=4i=4,popcount(A4)=2\text{popcount}(A_4)=2,有一个 jj 满足条件:A4⊕A6=5A_4\oplus A_6=5 且 popcount(A6)=2\text{popcount}(A_6)=2。

对于 i=5i=5,popcount(A5)=1\text{popcount}(A_5)=1,有一个 jj 满足条件:A5⊕A6=11A_5\oplus A_6=11 且 popcount(A6)=2\text{popcount}(A_6)=2。

对于 i=6i=6,popcount(A6)=2\text{popcount}(A_6)=2,有零个 jj 满足条件。

数据规模

对于 20%20\% 的数据,n≤1000n\leq 1000。

另有 30%30\% 的数据,X,Ai≤1000X,A_i\leq 1000。

对于 100%100\% 的数据,1≤n≤2×1051\leq n\leq 2\times 10^5,0≤X,Ai≤1090\leq X,A_i\leq 10^9。