CF1327F.AND Segments

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given three integers nn, kk, mm and mm conditions (l1,r1,x1),(l2,r2,x2),…,(lm,rm,xm)(l_1, r_1, x_1), (l_2, r_2, x_2), \dots, (l_m, r_m, x_m).

Calculate the number of distinct arrays aa, consisting of nn integers such that:

  • 0≤ai<2k0 \le a_i \lt 2^k for each 1≤i≤n1 \le i \le n;
  • bitwise AND of numbers a[li]&a[li+1]&…&a[ri]=xia[l_i] \& a[l_i + 1] \& \dots \& a[r_i] = x_i for each 1≤i≤m1 \le i \le m.

Two arrays aa and bb are considered different if there exists such a position ii that ai≠bia_i \neq b_i.

The number can be pretty large so print it modulo 998244353998244353.

给你三个整数 nn、kk、mm,以及 mm 个条件 (l1,r1,x1),(l2,r2,x2),…,(lm,rm,xm)(l_1, r_1, x_1), (l_2, r_2, x_2), \dots, (l_m, r_m, x_m)。

请计算满足以下条件的、由 nn 个整数组成的不同数组 aa 的个数:

  • 对每个 1≤i≤n1 \le i \le n,均有 0≤ai<2k0 \le a_i \lt 2^k;
  • 对每个 1≤i≤m1 \le i \le m,子数组 a[li]&a[li+1]&…&a[ri]a[l_i] \& a[l_i + 1] \& \dots \& a[r_i] 的按位与结果等于 xix_i。

若存在某个位置 ii 使得 ai≠bia_i \neq b_i,则称两个数组 aa 和 bb 不同。

答案可能非常大,请对 998244353998244353 取模后输出。

输入格式

The first line contains three integers nn, kk and mm (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5, 1≤k≤301 \le k \le 30, 0≤m≤5⋅1050 \le m \le 5 \cdot 10^5) — the length of the array aa, the value such that all numbers in aa should be smaller than 2k2^k and the number of conditions, respectively.

Each of the next mm lines contains the description of a condition lil_i, rir_i and xix_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, 0≤xi<2k0 \le x_i \lt 2^k) — the borders of the condition segment and the required bitwise AND value on it.

第一行包含三个整数 nn、kk 和 mm(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5,1≤k≤301 \le k \le 30,0≤m≤5⋅1050 \le m \le 5 \cdot 10^5),分别表示数组 aa 的长度、要求数组 aa 中所有数均小于 2k2^k 的参数 kk,以及约束条件的个数。

接下来的 mm 行每行描述一个约束条件,包含 lil_i、rir_i 和 xix_i(1≤li≤ri≤n1 \le l_i \le r_i \le n,0≤xi<2k0 \le x_i \lt 2^k),分别表示该约束条件对应区间的左右端点以及该区间上所有元素按位与(bitwise AND)运算结果的要求值。

输出格式

Print a single integer — the number of distinct arrays aa that satisfy all the above conditions modulo 998244353998244353.

输出一个整数——满足上述所有条件的不同数组 aa 的个数对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    4 3 2
    1 3 3
    3 4 6

    输出#1

    3
  • 输入#2

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

    输出#2

    33

说明/提示

You can recall what is a bitwise AND operation here.

In the first example, the answer is the following arrays: [3,3,7,6][3, 3, 7, 6], [3,7,7,6][3, 7, 7, 6] and [7,3,7,6][7, 3, 7, 6].

你可以在这里回顾什么是按位与(bitwise AND)运算:链接。

在第一个例子中,答案是以下数组:[3,3,7,6][3, 3, 7, 6]、[3,7,7,6][3, 7, 7, 6] 和 [7,3,7,6][7, 3, 7, 6]。

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

首页