QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#16846. 预测位置

Statistics

一个升序排列且元素互不相同的整数键值数组 $x_i$ 以及一个非负整数常数 $\varepsilon$。

需要将原始键值数组划分为最少数量的子数组,使得对于每个子数组 $[l \dots r]$,都存在某个线性函数 $f(x) = k \cdot x + b$,用于预测键值 $x_i$ 在该子数组中的位置(即 $i - l$),且预测误差不超过 $\varepsilon$。

形式化地,对于第 $j$ 个子数组,必须存在系数 $k_j$ 和 $b_j$(不一定是整数),使得对于该子数组 $i \in [l_j \dots r_j]$ 中的所有键值 $x_i$,以下式子均成立:

$$|f_j(x_i) - (i - l_j)| \le \varepsilon$$

$$f_j(x) = k_j \cdot x + b_j$$

输入格式

输入数据的第一行包含两个由空格隔开的整数:$n$ 和 $\varepsilon$,分别表示键值的数量和最大允许误差($2 \le n \le 10^6$,$0 \le \varepsilon \le n$)。

输入数据的第二行包含按升序排列且互不相同的键值 $x_i$,两两之间由空格隔开($-2 \cdot 10^9 \le x_1 < x_2 < \dots < x_n \le 2 \cdot 10^9$)。

输出格式

在输出数据的一行中,输出一个整数 $m$ — 表示为了满足要求,将原始键值数组划分成的最少子数组数量。

样例

输入样例 1

8 0
1 2 3 4 7 10 13 16

输出样例 1

2

说明

在样例中,你可以将给定的键值数组划分为两个子数组:$[1, 2, 3, 4]$ 和 $[7, 10, 13, 16]$。对于第一个子数组,键值位置可以通过函数 $f(x) = x - 1$ 进行精确预测。对于第二个子数组,键值位置可以通过函数 $f(x) = (x - 7)/3 = 1/3 \cdot x - 7/3$ 进行精确预测。

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.