#P5280. [ZJOI2019] 线段树

[ZJOI2019] 线段树

Description

Jiutiao Kelian is a girl who likes data structures. Among common data structures, her favorite is the segment tree.

The core of a segment tree is lazy propagation. Below is pseudocode for a segment tree with lazy tags, where the array tagtag is the lazy tag:

Here, the function Lson(Node)\operatorname{Lson}(Node) denotes the left child of NodeNode, and Rson(Node)\operatorname{Rson}(Node) denotes the right child of NodeNode.

Now Kelian has a segment tree over [1,n][1,n], with index 11. All nodes in this segment tree have tag=0tag = 0. Then Kelian performs mm operations. There are two types of operations:

  • 1 l r1\ l\ r: Suppose Kelian currently has tt segment trees. She will copy each segment tree into two copies (the tagtag array is copied as well). The segment tree originally indexed ii becomes two copied trees indexed 2i12i-1 and 2i2i. After copying, she has 2t2t segment trees in total. Then, she performs Modify(root,1,n,l,r)\operatorname{Modify}(root,1,n,l,r) once on every segment tree whose index is odd.

  • 22: Kelian defines the weight of a segment tree as the number of nodes in it whose tagtag equals 11. She wants to know the sum of weights of all segment trees she currently has.

Input Format

The first line contains two integers n,mn,m, denoting the initial interval length and the number of operations.

Each of the next mm lines describes one operation. The input guarantees 1lrn1 \le l \le r \le n.

Output Format

For each query, output one integer per line representing the answer. The answer can be very large, so output it modulo 998244353998244353.

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

Hint

The segment tree over [1,5][1,5] is shown below:

At the first query, Kelian has one segment tree, and there are no marks on any node, so the answer is 00.

At the second query, Kelian has two segment trees. By their indices, their marked nodes are:

  1. Node [1,3][1,3] is marked, so the weight is 11.
  2. No node is marked, so the weight is 00.

So the answer is 11.

At the third query, Kelian has four segment trees. By their indices, their marked nodes are:

  1. Nodes [1,2],[3,3],[4,5][1,2],[3,3],[4,5] are marked, so the weight is 33.
  2. Node [1,3][1,3] is marked, so the weight is 11.
  3. Nodes [3,3],[4,5][3,3],[4,5] are marked, so the weight is 22.
  4. No node is marked, so the weight is 00.

So the answer is 66.

Test Point nn mm Other Constraints
11 1000\le 1000 10\le 10 None
22 ^ ^ ^
33 1000\le 1000
44 ^
55 105\le 10^5 There is only one query
66 ^ ^
77
88 None
99 ^
1010

For 100%100\% of the data, 1lrn1 \le l \le r \le n.

Translated by ChatGPT 5