This page is still under construction.

Parts of this page are still being built. What you see may change.

The Grand Noi and ICPC Battle

Time limit2sMemory limit512 MB

Summary
Maintain a sequence of N ones under range assignment and queries for the sum of A_i A_j A_k over all i<j<k in a range, modulo 10^8, with N up to 1e9 and Q up to 1e5.
Level

Hard8 of 10

Topics
Segment tree, Divide and conquer, Math, Combinatorics
Solved
No attempts yet

Problem

The Nois are an ancient and cultured race with a strange fascination for mathematics and computers. They are a peaceful race, but they are now engaged in an epic war against their feared foes, the Inter-continental Prairie Corgis (known as the ICPCs in short). The war has been in progress for years, and neither side has managed to make footholds in their opponent's territory.

But now the Nois have a grand plan to finally end the war and return to their normal activities of discovering new theorems and inventing math problems. The Nois, with their devastating intellects, have managed to create a superweapon that will blast the ICPCs into an alternate dimension where math and computers do not exist. (The very thought that such a dimension exists chills their bones, and the poor Noi who discovered the dimension is now locked in a psychiatric ward. But that is for another story.) Alas, ICPC spies discovered their plan, and a saboteur managed to sneak in and ruin the configuration of the Noi superweapon.

The superweapon is configured using a sequence of NN integers, and the Nois have devised a way to rapidly test for the right configuration. However, the only Noi who can write code to perform the tests is in a psychiatric ward, and they now desperately need help. The Nois have heard of your programming prowess, and have enlisted your help in reconfiguring their superweapon.

They sent you this message. Help us, oh great one! We need a program to help defeat the dastardly ICPCs. When looking for the right configuration of our superweapon, we perform either of two operations on our configuration sequence (which we will refer to as AA): we either set AL,AL+1,…,AR−1,ARA_L, A_{L+1}, \dots, A_{R-1}, A_R to VV (for some integers LL and RR), or we try to find the sum of all AiAjAkA_i A_j A_k over the indices ii, jj, kk such that L≤i<j<k≤RL \le i < j < k \le R (for some integers LL and RR).

Input

The first line of input contains two integers NN and QQ, separated by a single space, where NN is the length of the configuration sequence and QQ is the number of operations that the Nois have to perform.

The next QQ lines contain the operations to be performed on the configuration sequence in order, and are in either of the two following formats:

  • SET L R V: set all of AL,AL+1,…,AR−1,ARA_L, A_{L+1}, \dots, A_{R-1}, A_R to VV.
  • ASK L R: output the sum of all AiAjAkA_i A_j A_k over the indices ii, jj, kk such that L≤i<j<k≤RL \le i < j < k \le R, modulo 10810^8.

Every element of the configuration sequence is initially set to 1.

Constraints:

  • 1≤N≤1091 \le N \le 10^9
  • 1≤Q≤1051 \le Q \le 10^5
  • 1≤L≤R≤N1 \le L \le R \le N
  • 1≤V≤1061 \le V \le 10^6

Output

Output MM lines, where MM is the number of operations of the second kind. For each such line, output a single integer SS, which is the sum of all AiAjAkA_i A_j A_k over the indices ii, jj, kk such that L≤i<j<k≤RL \le i < j < k \le R, modulo 10810^8. If fewer than three indices lie in the range, the sum is empty and the answer is 0.

Examples4

  1. Example 1

    Input
    10 9
    ASK 1 4
    ASK 3 10
    SET 5 10 3
    ASK 1 4
    ASK 3 10
    SET 4 6 10000
    ASK 1 4
    ASK 3 10
    ASK 3 4
    
    Expected output
    4
    56
    4
    828
    30001
    1980162
    0
    
  2. Example 2

    Input
    1 4
    ASK 1 1
    SET 1 1 1000000
    ASK 1 1
    ASK 1 1
    
    Expected output
    0
    0
    0
    
  3. Example 3

    Input
    2 4
    ASK 1 2
    ASK 2 2
    SET 1 2 1000000
    ASK 1 2
    
    Expected output
    0
    0
    0
    
  4. Example 4

    Input
    3 6
    ASK 1 3
    SET 2 2 1000000
    ASK 1 3
    SET 1 3 1000000
    ASK 1 3
    ASK 2 3
    
    Expected output
    1
    1000000
    0
    0