#P3774. [CTSC2017] 最长上升子序列

    ID: 1392 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2017WC/CTSC/集训队网络流O2优化

[CTSC2017] 最长上升子序列

Description

Zhu Xiaoxia recently studied the longest increasing subsequence (LIS). For an integer sequence A=(a1,a2,,ak)A =(a_1, a_2,\ldots , a_k), a subsequence of AA is defined as the sequence formed by deleting some elements from AA (deleting none or all kk 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 AA. Among them, an increasing subsequence with the largest number of elements is called a longest increasing subsequence of AA. For example, (2,4,5,6)(2, 4, 5, 6) and (1,4,5,6)(1, 4, 5, 6) are both longest increasing subsequences of (2,1,1,4,7,5,6)(2, 1, 1, 4, 7, 5, 6), and their lengths are both 44.

Now Zhu Xiaoxia encounters the following problem: given a sequence Bm=(b1,b2,,bm)B_m = (b_1, b_2, \ldots, b_m), let CC be a subsequence of BmB_m. If the length of the LIS of CC does not exceed kk, what is the maximum possible length of CC?

Zhu Xiaoxia thinks this problem is too easy and lacks challenge, so he proposes a harder one. He gives you a sequence B=(b1,b2,,bn)B = (b_1, b_2,\ldots , b_n) and several queries. Each query gives two integers mm and kk. For the sequence formed by the first mm elements of BB, namely Bm=(b1,b2,,bm)B_m = (b_1, b_2, \ldots, b_m), and the given kk, you need to answer the problem above.

Input Format

The first line contains two integers n,qn, q, where nn is the length of the sequence BB, and qq is the number of queries.

The second line contains nn space-separated positive integers b1,b2,,bnb_1, b_2, \ldots, b_n.

The next qq lines follow. The ii-th line contains two integers mi,kim_i, k_i, representing a query with m=mim = m_i and k=kik = k_i.

Output Format

Output qq 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 11: For the sequence (9,6,3,1,5)(9,6,3,1,5), one may choose the subsequence (9,6,3,1)(9,6,3,1), whose LIS length is 11.

Query 22: For the sequence (9,6,3,1,5,12,8)(9,6,3,1,5,12,8), one may choose the subsequence (9,6,3,1,12,8)(9,6,3,1,12,8), whose LIS length is 22.

Query 33: For the sequence (9,6,3,1,5,12,8,4,2)(9,6,3,1,5,12,8,4,2), one may choose the subsequence (9,6,5,4,2)(9,6,5,4,2), whose LIS length is 11.

Query 44: For the sequence (9,6,3,1,5,12,8,4,2)(9,6,3,1,5,12,8,4,2), one may choose the subsequence (9,6,3,1,12,8,4,2)(9,6,3,1,12,8,4,2), whose LIS length is 22.

Query 55: For the sequence (9,6,3,1,5,12,8,4,2,2,2)(9,6,3,1,5,12,8,4,2,2,2), one may choose the subsequence (9,6,5,4,2,2,2)(9,6,5,4,2,2,2), whose LIS length is 11.

Query 66: For the sequence (9,6,3,1,5,12,8,4,2,2,2)(9,6,3,1,5,12,8,4,2,2,2), one may choose the subsequence (9,6,3,1,5,12,8,4,2,2,2)(9,6,3,1,5,12,8,4,2,2,2), whose LIS length is 33.

Constraints: For 100%100\% of the testdata, 1n5×1041 \le n \le 5 \times 10^4, 1bi5×1041 \le b_i \le 5 \times 10^4, 1q2×1051 \le q \le 2 \times 10^5, 1kimin1 \le k_i \le m_i \le n.

Translated by ChatGPT 5