#7597. [MCO 2025] Subsequence
[MCO 2025] Subsequence
[MCO 2025] Subsequence
题目描述
Given an array $a$ and an integer $X$, you are tasked to find the longest $\textbf{valid}$ subsequence of the array $a$. A subsequence is $\textbf{valid}$ if and only if none of the products of neighbouring elements in the subsequence exceed $X$. That is, suppose $b$ is the subsequence of $a$ with length $m$, $b$ is $\textbf{valid}$ if and only if for any $i$, where $1 \leq i \leq m-1$, $b_i \cdot b_{i+1} \leq X$.Note: An array is a subsequence of another array if can be created by removing some elements (possibly none) from array without changing the order of elements. For example, the array is a subsequence of , whereas the array and the array is \textbf{not} a subsequence of .
输入格式
The first line contains two space-seperated integers, $n$ ($1 \leq n \leq 10^5$) and $X$ ($0 \leq |X| \leq 10^{18}$) -- $n$ is the length of array $a$ and $X$ is the integer given.The second line contains space-seperated integers, ().
输出格式
The only line contains an integer, which is the length of the longest $\textbf{valid}$ subsequence.1 10
100
1
5 10
3 4 2 5 1
4
5 10
6 -2 -2 -6 5
4
提示
### NoteA subsequence of one element is always valid because there are no neighbouring elements. Therefore, the length of the longest subsequence is .
This example has a subsequence, . It is because the product of the neighbouring elements does not exceed , as shown below.
The subsequence (i.e., the original array ) is because the product of the first and second elements is 12, which exceeds .
Therefore, the length of the longest subsequence is .
The longest subsequence is .
The subsequence (i.e., the original array ) is because the product of the third and fourth elements is , which exceeds .
Scoring
Subtask 1 ( points):
Subtask 2 ( points):
Subtask 3 ( points):
Subtask 4 ( points): and , for all
Subtask 5 ( points): and , for all
Subtask 6 ( points): and , for all
Subtask 7 ( points): No additional constraints 标签: P15278|动态规划 DP|线段树|2025|MCC/MCO(马来西亚)