Task
The following problem was passed down through the generations in the InfO(1)Cup Kingdom - can you solve it?
You are given a sequence of non-negative integers, and queries of the form for . For each query, compute:
For example, if , , , , , then the answer is .
Implementation details
You should implement the following function:
std::vector<long long> solve(
int N, int Q,
std::vector<int> A,
std::vector<int> L,
std::vector<int> R,
std::vector<int> M
);
This function should return the answer for the given instructions. It will only be called once per execution by the committee's grader. Note that the array is indexed from to , and the arrays , , are indexed from to .
Remember to include the header modulosum.h
! Also, remember that you should not implement the main
function, only solve
.
Sample grader behaviour
The sample grader will read , , the array , then triplets . It will then call , and output the returned values to standard output, one on a line. The input/output files below work for this grader.
Constraints and clarifications
- ;
- ;
- ;
- ;
- .
# | Points | Restrictions |
---|---|---|
1 | 8 | |
2 | 5 | , |
3 | 9 | |
4 | 11 | |
5 | 25 | |
6 | 42 | No further restrictions. |
Example 1
stdin
5 4
5 1 4 2 3
0 2 4
1 4 3
2 3 3
0 4 10
stdout
2
4
3
15
Explanation
In the first question, mod mod mod .
In the second question, mod mod mod mod .
In the third question, mod mod .
In the fourth question, mod mod mod mod mod .