#P13818. 「LDOI R3」泡泡抗特

「LDOI R3」泡泡抗特

题目背景

somewhere  \ over  \ the rainbow  \ way up  \ high.
there's a land  \ that i heard of once  \ in a lullaby.
only blue. only blue.  \ 愛讓人,好憂鬱。
我的心。我的心。藍藍的。

题目描述

给定长度为 nn 的正整数序列 a1,a2,,ana_1, a_2, \ldots,a_n

求满足以下条件的正整数三元组 (i,j,k)(i,j,k) 的个数:

  • 1i<j<kn1\le i < j < k \le n
  • popcount(aiaj)2\mathrm{popcount}(a_i\oplus a_j) \le 2
  • popcount(aiak)2\mathrm{popcount}(a_i\oplus a_k) \le 2
  • popcount(akaj)2\mathrm{popcount}(a_k\oplus a_j) \le 2
  • aiajak=0a_i \oplus a_j \oplus a_k = 0

你只需要输出答案模 109+710^9 + 7 的值。

其中 \oplus 代表二进制下的按位异或运算。

::::info[popcount\mathrm{popcount} 是什么?] 对于正整数 xx,我们定义 popcount(x)\mathrm{popcount}(x)xx 在二进制下 11 的个数。

例如,11=(1011)211 = (1011)_2,因此 popcount(11)=3\mathrm{popcount}(11) = 3。 ::::

输入格式

本题有多组测试数据。

每个输入数据第一行有一个整数 TT

每组测试第一行输入一个正整数 nn
每组测试第二行输入 nn 个正整数,第 ii 个正整数代表 aia_i

输出格式

每组测试输出一行一个整数,代表答案模 109+710^9 + 7 的值。

2
3
1 1 1
5
1 2 3 4 5
0
2

提示

【样例解释】

  • 第一组输入没有合法的三元组。
  • 第二组输入有 (i,j,k)=(1,2,3),(1,4,5)(i, j, k) = (1,2,3),(1,4,5) 两组合法。

【数据范围与约定】

对于 100%100\% 的数据,保证:

  • 1n3×1051\le n\le 3\times 10^5
  • 1ai21201\le a_i\le 2^{120}
  • 1T101\le T\le 10

::cute-table{tuack}

Subtask\text{Subtask} nn\le aia_i\le 特殊性质 分数
1 1010 2302^{30} 1010
2 20002000 1515
3 10410^4
4 10510^5 2602^{60} A 55
5 B
6 2020
7 3×1053\times 10^5 21202^{120} 3030

特殊性质 A:对于任意 aia_i,满足 popcount(ai)=1\mathrm{popcount}(a_i)=1
特殊性质 B:满足 ai230a_i \ge 2^{30} 且数据随机。

【其它注意事项】

本题输入量较大,请使用较快的 IO 方式。

本题 aia_i 的范围较大,您可以使用 __int128

__int128 可以存储大致 21272^{127} 左右的数据,你可以用它存储 aia_i。但是,它并不支持传统的输入输出,因此我们提供了读入模板,你可以调用该函数读入 __int128

void redi (__int128& ret) {
    ret = 0; int f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-') f = -f; ch = getchar();}
    while (ch >= '0' && ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
    ret *= f;
} // 调用 redi(x) 以读入变量 x。