Once Divan analyzed a sequence a1,a2,…,an consisting of n non-negative integers as follows. He considered each non-empty subsequence of the sequence a, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence a.
A sequence c is a subsequence of a sequence d if c can be obtained from d by deletion of several (possibly, zero or all) elements. For example, [1,2,3,4], [2,4], and [2] are subsequences of [1,2,3,4], but [4,3] and [0] are not.
Divan was very proud of his analysis, but now he lost the sequence a, and also the coziness value! However, Divan remembers the value of bitwise OR on m contiguous subsegments of the sequence a. It turns out that each element of the original sequence is contained in at least one of these m segments.
Divan asks you to help find the coziness of the sequence a using the information he remembers. If several coziness values are possible, print any.
As the result can be very large, print the value modulo 109+7.
Input
The first line contains one integer number t (1≤t≤103) — the number of test cases.
The first line of each test case contains two integer numbers n and m (1≤n,m≤2⋅105) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.
The following m lines describe the segments, one per line.
Each segment is described with three integers l, r, and x (1≤l≤r≤n, 0≤x≤230−1) — the first and last elements of the segment and the bitwise OR of al,al+1,…,ar, respectively.
It is guaranteed that each element of the sequence is contained in at least one of the segments. It is guaranteed that there exists a sequence that satisfies all constraints.
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 2⋅105.
Output
For each test case print the coziness any suitable sequence a modulo 109+7.
Example
input
Copy
3 2 1 1 2 2 3 2 1 3 5 2 3 5 5 4 1 2 7 3 3 7 4 4 0 4 5 2
output
Copy
4 20 112
Note
In first example, one of the sequences that fits the constraints is [0,2]. Consider all its non-empty subsequences:
- [0]: the bitwise XOR of this subsequence is 0;
- [2]: the bitwise XOR of this subsequence is 2;
- [0,2]: the bitwise XOR of this subsequence is 2.
The sum of all results is 4, so it is the answer.
In second example, one of the sequences that fits the constraints is [0,5,5].
In third example, one of the sequences that fits the constraints is [5,6,7,0,2].
这个题是让你求数组a的全部子集的异或然后相加,给你的是子集的或值。
思路:我们可以先看数组a的舒适度求法,这个题让我们求的是全部子集的异或的和,我们一共有n个数,(此时先假设这个位上有a个1,那么将会有b个0,b=n-a)(此时a必须大于0,否则无法挑选,也就是下面某位全为0时,挑选方法有0种了)。挑选时:我们要对结果(所有异或的总和)产生贡献,就要选出奇数个1,我们在挑0时,有两种情况选和不选。
由公式得知最后答案与1的个数无关只有与n有关。现在再来处理或的值,只要有1,或的那一位就有1。或的某一位为0,说明不存在该位(n个数该位都为0,没有贡献)(或的作用就是填充1)(给出一段区间的或,可以将其中一个数变为该值,剩下的全为0)(没有对结果产生影响的不用看)
#include <iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll qmi(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
int l,r;
ll x,OR=0;
while(m--)
{
cin>>l>>r>>x;
OR|=x;
}
ll sum=qmi(2,n-1);
cout<<sum*OR%mod<<endl;
}
return 0;
}