문제
Bessie was recently taking a USACO contest and encountered the following problem. Of course, Bessie knows how to solve it. But do you?
Consider a sequence of length consisting solely of integers in the range You are given () queries of the form For each query, compute the number of non-decreasing subsequences of mod .
A non-decreasing subsequence of is a collection of indices such that and Make sure to consider the empty subsequence!
SCORING:
Test cases 2-3 satisfy . Test cases 4-6 satisfy Test cases 7-9 satisfy Test cases 10-12 satisfy no additional constraints.
입력
The first line contains two space-separated integers and .
The second line contains space-separated integers .
The third line contains a single integer
The next lines each contain two space-separated integers and
출력
For each query you should print the number of non-decreasing subsequences of mod on a new line.
예제 입력 1
5 2
1 2 1 1 2
3
2 3
4 5
1 5
예제 출력 1
3
4
20
코드를 제출하려면 로그인이 필요합니다.
로그인