QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100

#15891. Subsequence

الإحصائيات

给定一个数组 $a$ 和一个整数 $X$,你需要找出数组 $a$ 的最长合法子序列。一个子序列当且仅当其任意相邻元素的乘积都不超过 $X$ 时,才是合法的。也就是说,设 $b$ 是 $a$ 的一个长度为 $m$ 的子序列,则 $b$ 合法当且仅当对任意 $i$($1 \leq i \leq m-1$),都有 $b_i \cdot b_{i+1} \leq X$。

注意:数组 $b$ 是数组 $a$ 的子序列,指的是可以在不改变元素相对顺序的前提下,从 $a$ 中删除一些元素(也可以一个都不删)得到 $b$。例如,数组 $[1,3]$ 是 $[1,2,3]$ 的子序列,而数组 $[2,1]$ 和数组 $[1,4]$ 都不是 $[1,2,3]$ 的子序列。

输入格式

第一行包含两个用空格分隔的整数 $n$($1 \leq n \leq 10^5$)和 $X$($0 \leq |X| \leq 10^{18}$)——$n$ 为数组 $a$ 的长度,$X$ 为给定的整数。

第二行包含 $n$ 个用空格分隔的整数 $a_1, a_2, \dots, a_n$($1 \leq |a_i| \leq 10^9$)。

输出格式

仅一行包含一个整数,表示最长合法子序列的长度。

样例数据

输入

1 10
100

输出

1

解释

只包含一个元素的子序列总是合法的,因为不存在相邻元素。因此,最长合法子序列的长度为 $1$。

输入

5 10
3 4 2 5 1

输出

4

解释

本样例存在一个合法子序列 $[3,2,5,1]$。因为相邻元素的乘积不超过 $10$,如下所示:

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

子序列 $[\underline{3,4},2,5,1]$(即原数组 $a$)是不合法的,因为前两个元素的乘积为 $12$,超过了 $10$。

因此,最长合法子序列的长度为 $4$。

输入

5 10
6 -2 -2 -6 5

输出

4

解释

最长合法子序列为 $[6,-2,-2,5]$。

子序列 $[6,-2,\underline{-2, -6}, 5]$(即原数组 $a$)是不合法的,因为第三个与第四个元素的乘积为 $-2 \times -6 = 12$,超过了 $10$。

子任务

子任务 1($5$ 分):$X = 10^{18}$

子任务 2($15$ 分):$n \leq 20$

子任务 3($20$ 分):$n \leq 10^3$

子任务 4($10$ 分):$X \geq 0$ 且对所有 $1 \leq i \leq n$,$1 \leq a_i \leq 200$

子任务 5($20$ 分):$X \geq 0$ 且对所有 $1 \leq i \leq n$,$1 \leq a_i \leq 10^5$

子任务 6($10$ 分):$X \geq 0$ 且对所有 $1 \leq i \leq n$,$a_i \geq 1$

子任务 7($20$ 分):无额外限制

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.