CF1614C.Divan and bitwise operations

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Once Divan analyzed a sequence a1,a2,…,ana_1, a_2, \ldots, a_n consisting of nn non-negative integers as follows. He considered each non-empty subsequence of the sequence aa, computed the bitwise XOR of its elements and added up all the XORs, obtaining the coziness of the sequence aa.

A sequence cc is a subsequence of a sequence dd if cc can be obtained from dd by deletion of several (possibly, zero or all) elements. For example, [1, 2, 3, 4][1, \, 2, \, 3, \, 4], [2, 4][2, \, 4], and [2][2] are subsequences of [1, 2, 3, 4][1, \, 2, \, 3, \, 4], but [4, 3][4, \, 3] and [0][0] are not.

Divan was very proud of his analysis, but now he lost the sequence aa, and also the coziness value! However, Divan remembers the value of bitwise OR on mm contiguous subsegments of the sequence aa. It turns out that each element of the original sequence is contained in at least one of these mm segments.

Divan asks you to help find the coziness of the sequence aa 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+710^9 + 7.

Divan 曾对一个由 nn 个非负整数组成的序列 a1,a2,…,ana_1, a_2, \ldots, a_n 进行如下分析:他考虑该序列 aa 的每一个非空子序列,计算其所有元素的按位异或(XOR),然后将所有这些异或值求和,得到序列 aa 的舒适度(coziness)。

序列 cc 是序列 dd 的一个子序列,当且仅当 cc 可通过从 dd 中删除若干(可能为零个或全部)元素而得到。例如,[1, 2, 3, 4][1, \, 2, \, 3, \, 4]、[2, 4][2, \, 4] 和 [2][2] 都是 [1, 2, 3, 4][1, \, 2, \, 3, \, 4] 的子序列,但 [4, 3][4, \, 3] 和 [0][0] 不是。

Divan 对自己的分析非常自豪,但现在他丢失了原始序列 aa,也忘记了舒适度的值!不过,Divan 记得序列 aa 的 mm 个连续子段各自的按位或(OR)值。并且,原始序列的每个元素都至少被这 mm 个子段中的某一个所覆盖。

Divan 请求你利用他所记得的信息,帮助他还原出序列 aa 的舒适度。如果存在多种可能的舒适度值,输出任意一个即可。

由于结果可能非常大,请将答案对 109+710^9 + 7 取模后输出。

输入格式

The first line contains one integer number tt (1≤t≤1031 \le t \le 10^3) — the number of test cases.

The first line of each test case contains two integer numbers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the length of the sequence and the number of contiguous segments whose bitwise OR values Divan remembers, respectively.

The following mm lines describe the segments, one per line.

Each segment is described with three integers ll, rr, and xx (1≤l≤r≤n1 \le l \le r \le n, 0≤x≤230−10 \le x \le 2^{30} - 1) — the first and last elements of the segment and the bitwise OR of al,al+1,…,ara_l, a_{l + 1}, \ldots, a_r, 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 nn and the sum of mm over all test cases do not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示序列的长度以及 Divan 记得的连续区间的个数(这些区间的按位或值)。

接下来的 mm 行描述这些区间,每行描述一个区间。

每个区间由三个整数 ll、rr 和 xx(1≤l≤r≤n1 \le l \le r \le n,0≤x≤230−10 \le x \le 2^{30} - 1)描述,分别表示该区间的起始位置、结束位置,以及 al,al+1,…,ara_l, a_{l + 1}, \ldots, a_r 的按位或值。

保证序列中的每个元素至少被包含在其中一个区间内。保证存在至少一个满足所有约束条件的序列。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case print the coziness any suitable sequence aa modulo 109+710^9 + 7.

对于每个测试用例,输出任意一个满足条件的序列 aa 的“舒适度”对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    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

    输出#1

    4
    20
    112

说明/提示

In first example, one of the sequences that fits the constraints is [0,2][0, 2]. Consider all its non-empty subsequences:

  • [0][0]: the bitwise XOR of this subsequence is 00;
  • [2][2]: the bitwise XOR of this subsequence is 22;
  • [0,2][0, 2]: the bitwise XOR of this subsequence is 22.

The sum of all results is 44, so it is the answer.

In second example, one of the sequences that fits the constraints is [0, 5, 5][0, \, 5, \, 5].

In third example, one of the sequences that fits the constraints is [5, 6, 7, 0, 2][5, \, 6, \, 7, \, 0, \, 2].

在第一个例子中,一个满足约束条件的序列是 [0,2][0, 2]。考虑它的所有非空子序列:

  • [0][0]:该子序列的按位异或(XOR)结果为 00;
  • [2][2]:该子序列的按位异或(XOR)结果为 22;
  • [0,2][0, 2]:该子序列的按位异或(XOR)结果为 22。

所有结果之和为 44,因此答案为 44。

在第二个例子中,一个满足约束条件的序列是 [0, 5, 5][0, \, 5, \, 5]。

在第三个例子中,一个满足约束条件的序列是 [5, 6, 7, 0, 2][5, \, 6, \, 7, \, 0, \, 2]。

输入解题思路,AI测评打分。不知道怎么写?

首页