102557: [AtCoder]ABC255 Ex - Range Harvest Query

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

There are $N$ trees. On Day $0$, each tree bears no fruits.
On the morning of Day $1$ and subsequent days, the $i$-th tree bears $i$ new fruits for each $i = 1, 2, \ldots, N$.

Takahashi will perform $Q$ harvesting. For each $i = 1, 2, \ldots, Q$, the $i$-th harvesting takes place on the night of Day $D_i$, collecting all fruits remaining on the $L_i$-th through $R_i$-th trees at that point.

For each of the $Q$ harvesting, print the number of fruits Takahashi will collect, modulo $998244353$.

Constraints

  • $1 \leq N \leq 10^{18}$
  • $1 \leq Q \leq 2 \times 10^5$
  • $1 \leq D_1 \lt D_2 \lt \cdots \lt D_Q \leq 10^{18}$
  • $1 \leq L_i \leq R_i \leq N$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $Q$
$D_1$ $L_1$ $R_1$
$D_2$ $L_2$ $R_2$
$\vdots$
$D_Q$ $L_Q$ $R_Q$

Output

Print $Q$ lines. For each $i = 1, 2, \ldots, Q$, the $i$-th line should contain the number of fruits Takahashi will collect in the $i$-th harvesting, modulo $998244353$.


Sample Input 1

5 3
2 2 3
3 3 4
5 1 5

Sample Output 1

10
15
50

For each $i = 1, 2, 3, 4, 5$, let $A_i$ be the number of fruits remaining on the $i$-th tree. Now, we use the sequence $A = (A_1, A_2, A_3, A_4, A_5)$ to represent the numbers of fruits remaining in the trees.

  • On Day $0$, we have $A = (0, 0, 0, 0, 0)$.
  • On the morning of Day $1$, each tree bears new fruits, and we have $A = (1, 2, 3, 4, 5)$.
  • On the morning of Day $2$, each tree bears new fruits, and we have $A = (2, 4, 6, 8, 10)$.
  • On the night of Day $2$, Takahashi performs the $1$-st harvesting. $4 + 6 = 10$ fruits are collected, and we have $A = (2, 0, 0, 8, 10)$.
  • On the morning of Day $3$, each tree bears new fruits, and we have $A = (3, 2, 3, 12, 15)$.
  • On the night of Day $3$, Takahashi performs the $2$-nd harvesting. $3 + 12 = 15$ fruits are collected, and we have $A = (3, 2, 0, 0, 15)$.
  • On the morning of Day $4$, each tree bears new fruits, and we have $A = (4, 4, 3, 4, 20)$.
  • On the morning of Day $5$, each tree bears new fruits, and we have $A = (5, 6, 6, 8, 25)$.
  • On the night of Day $5$, Takahashi performs the $3$-rd harvesting. $5 + 6 + 6 + 8 + 25 = 50$ fruits are collected, and we have $A = (0, 0, 0, 0, 0)$.

Sample Input 2

711741968710511029 1
82803157126515475 516874290286751784 588060532191410838

Sample Output 2

603657470

Be sure to print the numbers modulo $998244353$.

Input

题意翻译

给定一片 $N$ 格的农田,从第 $0$ 天开始,第 $i$ 格农田每天会长出 $i$ 的作物。 给出 $Q$ 个询问,每次询问以 $D,L,R$ 的格式给出,表示询问在第 $D$ 天,收割 $[L,R]$ 的农田,会获得多少作物?答案对 $998244353$ 取模。注意询问相互依赖,即在每一次收割后,$[L,R]$ 的作物应当清零。

Output

得分:600分 部分 问题描述 有N棵树。在第0天,每棵树都不结水果。 在第1天的早晨和随后的每一天,第i棵树会结出i个新的水果,其中i=1,2,……,N。 Takahashi将进行Q次收获。 对于每次i=1,2,……,Q,第i次收获在第Di天的晚上进行,收集此时第Li棵树到第Ri棵树上剩余的所有水果。 对于这Q次收获,每次打印Takahashi将收集到的水果数量,对998244353取模。 部分 约束 1≤N≤1018 1≤Q≤2×105 1≤Di<Di+1<……<DQ≤1018 1≤Li≤Ri≤N 输入中的所有值都是整数。 部分 输入 输入通过标准输入给出,格式如下: N Q D1 L1 R1 D2 L2 R2 …… DQ LQ RQ 部分 输出 打印Q行。 对于每次i=1,2,……,Q,第i行应包含Takahashi在第i次收获中将收集到的水果数量,对998244353取模。 部分 样例输入1 5 3 2 2 3 3 3 4 5 1 5 部分 样例输出1 10 15 50 现在,我们使用序列A=(A1,A2,A3,A4,A5)来表示树上剩余的水果数量。 对于每次i=1,2,3,4,5,令Ai表示第i棵树上剩余的水果数量。 现在,我们使用序列A=(A1,A2,A3,A4,A5)来表示树上剩余的水果数量。 * 在第0天,我们有A=(0,0,0,0,0)。 * 在第1天的早晨,每棵树结出新的水果,我们有A=(1,2,3,4,5)。 * 在第2天的早晨,每棵树结出新的水果,我们有A=(2,4,6,8,10)。 * 在第2天的晚上,Takahashi进行第1次收获。收集到4+6=10个水果,我们有A=(2,0,0,8,10)。 * 在第3天的早晨,每棵树结出新的水果,我们有A=(3,2,3,12,15)。 * 在第3天的晚上,Takahashi进行第2次收获。收集到3+12=15个水果,我们有A=(3,2,0,0,15)。 * 在第4天的早晨,每棵树结出新的水果,我们有A=(4,4,3,4,20)。 * 在第5天的早晨,每棵树结出新的水果,我们有A=(5,6,6,8,25)。 * 在第5天的晚上,Takahashi进行第3次收获。收集到5+6+6+8+25=50个水果,我们有A=(0,0,0,0,0)。

加入题单

算法标签: