#7597. [MCO 2025] Subsequence

    ID: 7597 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P15278动态规划 DP线段树2025MCC/MCO(马来西亚)

[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 bb is a subsequence of another array aa if bb can be created by removing some elements (possibly none) from array aa without changing the order of elements. For example, the array [1,3][1,3] is a subsequence of [1,2,3][1,2,3], whereas the array [2,1][2,1] and the array [1,4][1,4] is \textbf{not} a subsequence of [1,2,3][1,2,3].

输入格式

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 nn space-seperated integers, a1,a2,…,ana_1, a_2, \dots, a_n (1≤∣ai∣≤1091 \leq |a_i| \leq 10^9).

输出格式

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

提示

### Note

Example1‾\underline{Example 1}\\ A subsequence of one element is always valid because there are no neighbouring elements. Therefore, the length of the longest valid\textbf{valid} subsequence is 11.

Example2‾\underline{Example 2}\\ This example has a valid\textbf{valid} subsequence, [3,2,5,1][3,2,5,1]. It is because the product of the neighbouring elements does not exceed 1010, as shown below.

  • 3×2=6 (≤10)3 \times 2 = 6 \,(\leq 10)
  • 2×5=10 (≤10)2 \times 5 = 10 \,(\leq 10)
  • 5×1=5 (≤5)5 \times 1 = 5 \,(\leq 5)

The subsequence [3,4‾,2,5,1][\underline{3,4},2,5,1] (i.e., the original array aa) is invalid\textbf{invalid} because the product of the first and second elements is 12, which exceeds 1010.

Therefore, the length of the longest valid\textbf{valid} subsequence is 44.

Example3‾\underline{Example 3}\\ The longest valid\textbf{valid} subsequence is [6,−2,−2,5][6,-2,-2,5].

The subsequence [6,−2,−2,−6‾,5][6,-2,\underline{-2, -6}, 5] (i.e., the original array aa) is invalid\textbf{invalid} because the product of the third and fourth elements is −2×−6=12-2 \times -6 = 12, which exceeds 1010.

Scoring

Subtask 1 (55 points): X=1018X = 10^{18}

Subtask 2 (1515 points): n≤20n \leq 20

Subtask 3 (2020 points): n≤103n \leq 10^3

Subtask 4 (1010 points): X≥0X \geq 0 and 1≤ai≤2001 \leq a_i \leq 200, for all 1≤i≤n1 \leq i \leq n

Subtask 5 (2020 points): X≥0X \geq 0 and 1≤ai≤1051 \leq a_i \leq 10^5, for all 1≤i≤n1 \leq i \leq n

Subtask 6 (1010 points): X≥0X \geq 0 and ai≥1a_i \geq 1, for all 1≤i≤n1 \leq i \leq n

Subtask 7 (2020 points): No additional constraints 标签: P15278|动态规划 DP|线段树|2025|MCC/MCO(马来西亚)

来源

P15278|[MCO 2025] Subsequence