#P3774. [CTSC2017] 最长上升子序列
[CTSC2017] 最长上升子序列
Description
Zhu Xiaoxia recently studied the longest increasing subsequence (LIS). For an integer sequence , a subsequence of is defined as the sequence formed by deleting some elements from (deleting none or all elements is allowed) while keeping the remaining elements in their original order. If the elements of this subsequence are strictly increasing from left to right, it is called an increasing subsequence of . Among them, an increasing subsequence with the largest number of elements is called a longest increasing subsequence of . For example, and are both longest increasing subsequences of , and their lengths are both .
Now Zhu Xiaoxia encounters the following problem: given a sequence , let be a subsequence of . If the length of the LIS of does not exceed , what is the maximum possible length of ?
Zhu Xiaoxia thinks this problem is too easy and lacks challenge, so he proposes a harder one. He gives you a sequence and several queries. Each query gives two integers and . For the sequence formed by the first elements of , namely , and the given , you need to answer the problem above.
Input Format
The first line contains two integers , where is the length of the sequence , and is the number of queries.
The second line contains space-separated positive integers .
The next lines follow. The -th line contains two integers , representing a query with and .
Output Format
Output lines. For each query, print one integer as the answer, in order.
11 6
9 6 3 1 5 12 8 4 2 2 2
5 1
7 2
9 1
9 2
11 1
11 11
4
6
5
8
7
11
Hint
Sample explanation:
Query : For the sequence , one may choose the subsequence , whose LIS length is .
Query : For the sequence , one may choose the subsequence , whose LIS length is .
Query : For the sequence , one may choose the subsequence , whose LIS length is .
Query : For the sequence , one may choose the subsequence , whose LIS length is .
Query : For the sequence , one may choose the subsequence , whose LIS length is .
Query : For the sequence , one may choose the subsequence , whose LIS length is .

Constraints: For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号