#5171. Problem 2. Non-Decreasing Subsequences
Problem 2. Non-Decreasing Subsequences
Problem 2. Non-Decreasing Subsequences
USACO 2020 January Contest, Platinum
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.
INPUT FORMAT (file nondec.in):
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
OUTPUT FORMAT (file nondec.out):
For each query you should print the number of non-decreasing subsequences of mod on a new line.
SAMPLE INPUT:
5 2 1 2 1 1 2 3 2 3 4 5 1 5
SAMPLE OUTPUT:
3 4 20
For the first query, the non-decreasing subsequences are and is not a non-decreasing subsequence because
For the second query, the non-decreasing subsequences are , , , and .
Problem credits: Benjamin Qi