Debug
Time limit3sMemory limit512 MB
Each call increments every index divisible by the given jump; answer range-sum queries over the resulting array.
- Level
Medium5 of 10
- Topics
- Array, Math, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Seán is debugging his own code. He first creates an array seq of integers and fills it with zeros. He then calls the following C++ function several times.
void something( int jump ) {
int i = 0;
while( i < N ) {
seq[i] = seq[i] + 1;
i = i + jump;
}
}
The function adds 1 to every element whose index is a multiple of jump. Index 0 is a multiple of every jump, so seq[0] grows by 1 on every call.
Seán calls the function exactly times and passes in that order.
Once the calls are done, Seán picks parts of the array he wants to check. Each part is given by its left bound and its right bound (). For each part, compute seq[L] + seq[L+1] + ... + seq[R].
Input
The first line contains the array size and the number of calls (, ).
The second line contains the arguments separated by spaces ().
The third line contains the number of parts ().
Each of the next lines contains two integers and ().
Output
Print lines. Line holds the value of seq[L_i] + seq[L_i + 1] + ... + seq[R_i].