QOJ.ac

QOJ

時間限制: 15 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#16891. 数列与查询与部分和之和

统计

有一个长度为 $N$ 的序列 $a_1, a_2, \dots, a_N$。初始时,所有 $a_i$ 均为 $0$。此时,可以使用以下查询来改变序列 $a$:

$l \ r \ c$:将序列 $a$ 中从第 $l$ 个到第 $r$ 个的值改为 $c$。

给定 $Q$ 个查询,定义 $f(U, D, L, R)$ 为“按顺序执行从第 $U$ 个到第 $D$ 个查询后,$a_L + a_{L+1} + \dots + a_R$ 的值”。如果多次执行 $f$,每次执行都是相互独立的,即前一次 $f$ 的执行不会影响当前 $f$ 的执行。

计算 $\sum_{U=1}^{Q} \sum_{D=U}^{Q} \sum_{L=1}^{N} \sum_{R=L}^{N} f(U, D, L, R)$ 对 $998\,244\,353$($= 119 \times 2^{23} + 1$)取模的结果。$998\,244\,353$ 是一个质数。

输入格式

第一行包含两个整数 $N, Q$($1 \le N, Q \le 300\,000$)。

从第二行开始,共 $Q$ 行,按顺序给出 $Q$ 个查询。第 $i$ 个查询包含三个整数 $l_i, r_i, c_i$($1 \le l_i \le r_i \le N; 0 \le c_i < 998\,244\,353$)。

输出格式

输出 $\sum_{U=1}^{Q} \sum_{D=U}^{Q} \sum_{L=1}^{N} \sum_{R=L}^{N} f(U, D, L, R)$ 对 $998\,244\,353$ 取模的结果。

样例

样例输入 1

2 2
1 2 1
2 2 2

样例输出 1

14

样例输入 2

10 10
10 10 593603443
4 9 993565789
3 8 238321270
7 8 424480868
10 10 556869540
8 10 279674600
7 8 575417117
6 8 948583421
6 6 468656456
4 10 865607491

样例输出 2

830609277

说明

对于第一个样例:

$f(1, 1, 1, 1) = 1$ $f(1, 1, 1, 2) = 1 + 1 = 2$ $f(1, 1, 2, 2) = 1$ $f(1, 2, 1, 1) = 1$ $f(1, 2, 1, 2) = 1 + 2 = 3$ $f(1, 2, 2, 2) = 2$ $f(2, 2, 1, 1) = 0$ $f(2, 2, 1, 2) = 0 + 2 = 2$ $f(2, 2, 2, 2) = 2$

因此,答案为 $1 + 2 + 1 + 1 + 3 + 2 + 0 + 2 + 2 = 14$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.