Shortsighted
InterviewTime limit2sMemory limit512 MB
Start with a zero array; range-update queries add a triangular weight pattern to each position, and range-sum queries report the total modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Prefix sum, Math, Implementation, Array
- Solved
- No attempts yet
Problem
While practicing for The 2019 ICPC Asia Jakarta Regional Contest, Budi stumbled upon an interesting problem on data structure topic. Unfortunately, he misread the problem, but he argues that the problem he thinks of is much more interesting than the original one, thus, this problem.
Let function on an array of integers be defined as incrementing every element in the subarray each by 1 for all . In other words, function can be written as follows (in pseudocode).
function f(L, R):
FOR i from L to R
FOR j from i to R
FOR k from i to j
Ak = Ak + 1
Given an array of elements (initially for all ), your task is to perform queries on of the following types.
1 L R— perform on .2 L R— output the sum of all where .
Input
Input begins with a line containing two integers: () representing the size of and the number of queries, respectively. The next lines each contains a query of the following types.
1 L R()2 L R()
There is at least one query of the second type.
Output
For each query of the second type in the same order as input, output in a line an integer representing the sum of all where . As this output can be large, you need to modulo the output by .