CF416D.Population Size

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions.

Polycarpus believes that if he writes out the population of the capital for several consecutive years in the sequence _a_1, _a_2, ..., a__n, then it is convenient to consider the array as several arithmetic progressions, written one after the other. For example, sequence (8, 6, 4, 2, 1, 4, 7, 10, 2) can be considered as a sequence of three arithmetic progressions (8, 6, 4, 2), (1, 4, 7, 10) and (2), which are written one after another.

Unfortunately, Polycarpus may not have all the data for the n consecutive years (a census of the population doesn't occur every year, after all). For this reason, some values of a__i may be unknown. Such values are represented by number -1.

For a given sequence a = (_a_1, _a_2, ..., a__n), which consists of positive integers and values -1, find the minimum number of arithmetic progressions Polycarpus needs to get a. To get a, the progressions need to be written down one after the other. Values -1 may correspond to an arbitrary positive integer and the values a__i > 0 must be equal to the corresponding elements of sought consecutive record of the progressions.

Let us remind you that a finite sequence c is called an arithmetic progression if the difference c__i + 1 - c__i of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.

波利卡普斯提出了一种关于等差数列与世间万物之间相互关系的有趣理论。他当前的想法是:贝尔兰首都的人口随时间变化遵循等差数列规律,或者更一般地,由若干个等差数列拼接而成。

波利卡普斯认为,若将首都连续若干年的人口数据按顺序写成序列 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n,则可将该数组视作若干个首尾相接的等差数列。例如,序列 (8, 6, 4, 2, 1, 4, 7, 10, 2)(8,\,6,\,4,\,2,\,1,\,4,\,7,\,10,\,2) 可被看作三个等差数列 (8, 6, 4, 2)(8,\,6,\,4,\,2)、(1, 4, 7, 10)(1,\,4,\,7,\,10) 和 (2)(2) 首尾相接而成。

遗憾的是,波利卡普斯可能并未掌握全部 nn 年的连续人口数据(毕竟人口普查并非每年进行)。因此,部分 aia_i 的值可能未知,这些未知值用 −1-1 表示。

给定一个由正整数和 −1-1 组成的序列 a=(a1, a2, …, an)a = (a_1,\,a_2,\,\dots,\,a_n),请找出波利卡普斯为复原出 aa 所需的最少等差数列个数。这些等差数列需首尾相接构成 aa。其中,值为 −1-1 的位置可对应任意正整数;而所有已知的 ai>0a_i > 0 必须严格等于所求拼接序列中对应位置的元素。

我们提醒您:有限序列 cc 被称为等差数列,当且仅当其任意两个相邻元素之差 ci+1−cic_{i+1} - c_i 为常数。根据定义,任何长度为 11 的序列均为等差数列。

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values _a_1, _a_2, ..., a__n separated by a space (1 ≤ a__i ≤ 109 or a__i =  - 1).

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)—— 表示序列中元素的个数。
第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,以空格分隔(1≤ai≤1091 \leq a_i \leq 10^9 或 ai=−1a_i = -1)。

输出格式

Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.

输出得到序列 aa 所需拼接的等差数列的最少个数。序列 aa 中标记为 −1-1 的位置可用任意正整数填充。

输入输出样例

  • 输入#1

    9
    8 6 4 2 1 4 7 10 2

    输出#1

    3
  • 输入#2

    9
    -1 6 -1 2 -1 4 7 -1 2

    输出#2

    3
  • 输入#3

    5
    -1 -1 -1 -1 -1

    输出#3

    1
  • 输入#4

    7
    -1 -1 4 5 1 2 3

    输出#4

    2

输入解题思路,AI测评打分。不知道怎么写?

首页