Under construction

Still being built. Things may change

Zoom

Time limit3sMemory limit1024 MB

Summary
Maintain an array under range additions, block copies that repeat a pair of cells, and full replays of past queries, then print range sums modulo 998244353.
Level

Hard8 of 10

Topics
Segment tree, Simulation
Solved
No attempts yet

Problem

Sequence AA of even length NN is given. Initially, every element of AA is 00. Process the following queries.

  • 1 l r b: Add bb to each of Al,Al+1,⋯ ,ArA_l, A_{l+1}, \cdots, A_r.
  • 2 l: For every integer ii with 1≤i≤N1 \leq i \leq N, replace AiA_i with Al+⌊i−12⌋A_{l+\lfloor \frac{i-1}{2} \rfloor}. All replacements happen simultaneously.
  • 3: Re-run all type 1 and type 2 queries processed so far, in the same order. Queries that were executed by earlier type 3 queries are included.
  • 4 l r: Print ∑i=lrAi\sum_{i=l}^r A_i modulo 998 244 353998\,244\,353.

Input

The first line contains the length NN of the sequence and the number of queries QQ, separated by a space.

Each of the next QQ lines contains one query.

Output

For each type 4 query, print the answer on its own line.

Constraints

  • 2≤N≤100 0002 \leq N \leq 100\,000, and NN is even.
  • 1≤Q≤100 0001 \leq Q \leq 100\,000.
  • For every type 1 query, 1≤l≤r≤N1 \leq l \leq r \leq N and 1≤b≤998 244 3521 \leq b \leq 998\,244\,352.
  • For every type 2 query, 1≤l≤N2+11 \leq l \leq \frac{N}{2}+1.
  • For every type 4 query, 1≤l≤r≤N1 \leq l \leq r \leq N.
  • At least one type 4 query appears in the input.
  • All given numbers are integers.

Examples3

  1. Example 1

    Input
    6 9
    1 1 5 2
    1 5 6 3
    2 4
    4 1 1
    4 2 2
    4 3 3
    4 4 4
    4 5 5
    4 6 6
    
    Expected output
    2
    2
    5
    5
    3
    3
    
  2. Example 2

    Input
    6 11
    1 1 5 2
    1 5 6 3
    3
    3
    3
    4 1 1
    4 2 2
    4 3 3
    4 4 4
    4 5 5
    4 6 6
    
    Expected output
    16
    16
    16
    16
    40
    24
    
  3. Example 3

    Input
    8 8
    1 2 5 1
    2 3
    3
    4 1 8
    1 2 5 2
    2 4
    3
    4 1 8
    
    Expected output
    14
    42