The Grand Noi and ICPC Battle
Time limit2sMemory limit512 MB
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 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 ): we either set to (for some integers and ), or we try to find the sum of all over the indices , , such that (for some integers and ).
Input
The first line of input contains two integers and , separated by a single space, where is the length of the configuration sequence and is the number of operations that the Nois have to perform.
The next 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 to .ASK L R: output the sum of all over the indices , , such that , modulo .
Every element of the configuration sequence is initially set to 1.
Constraints:
Output
Output lines, where is the number of operations of the second kind. For each such line, output a single integer , which is the sum of all over the indices , , such that , modulo . If fewer than three indices lie in the range, the sum is empty and the answer is 0.