#BS0000210. Truy vấn dãy con tăng trên tiền tố (Prefix LIS Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn dãy con tăng trên tiền tố (Prefix LIS Query)
Prefix LIS Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An integer sequence and queries are given. Query specifies a prefix ending at position and an upper value bound . Choose positions such that . The positions need not be consecutive. Find the maximum for each query independently; queries never change the sequence. At least one element of the prefix is at most .
Input
The first line contains integers , the sequence length and query count. The second line contains integers . Each of the next lines contains the two integers of query .
Output
Print lines, with the maximum length for query on line .
Subtasks
- Subtask 1 (20 points): ; (); ; ().
- Subtask 2 (30 points): ; (); ; ().
- Subtask 3 (50 points): ; (); ; ().
Examples
Input
5 3
2 4 1 3 3
2 5
5 2
5 3
Output
2
1
2
Explanation
The sequence is . Query permits both initial values, 2 and 4, so the length is 2. Query permits only 2 and 1, in decreasing order, so the best length is 1. Query permits in that order; has length 2. The two 3s cannot both be selected and 2 precedes 1, so no length 3 is possible. The answers are 2, 1 and 2.