codeforce 241div2 D

D. Population Size
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 a1, a2, ..., an, 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 ai ​​may be unknown. Such values are represented by number -1.

For a given sequence a = (a1, a2, ..., an), 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 ai > 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 ci + 1 - ci of any two consecutive elements in it is constant. By definition, any sequence of length 1 is an arithmetic progression.

Input

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 a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai =  - 1).

Output

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.

Sample test(s)
input
9
8 6 4 2 1 4 7 10 2
output
3
input
9
-1 6 -1 2 -1 4 7 -1 2
output
3
input
5
-1 -1 -1 -1 -1
output
1
input
7
-1 -1 4 5 1 2 3
output

2



题意: 给一个数列,每一项都大于0,有些项不知道是多少,用-1代替,-1可以代表任何数,可以修改,问最多可以形成多少个等差子数列,


#include<stdio.h>
#include <iostream>
using namespace std;

int n,ans;
long long a[1000100],cha;

int main()
{

	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%I64d",&a[i]);
	for(int i=1,j,k,l;i<=n;)
	{
		ans++;
		///cout<<i<<endl;
		for(j=i;j<=n&&a[j]==-1;j++);
		for(k=j+1;k<=n&&a[k]==-1;k++);
		if(k>n)break;
		if((a[k]-a[j])%(k-j))
		{
			i=k;
			continue;
		}
		cha=(a[k]-a[j])/(k-j);///公差
		if(a[k]-cha*(k-i)<=0)
		{
			i=k;
			continue;
		}

    for(i=k+1;i<=n&&a[k]+cha*(i-k)>0&&(a[i]==-1||a[i]==a[k]+cha*(i-k));i++);
		///吸收-1,或者是刚刚好是等差数列中的项
	}
	printf("%d",ans);
}


### 如何在 Codeforces 平台上将界面语言设置为中文 Codeforces 是一个国际化的编程竞赛平台,支持多种语言的界面显示,其中包括中文。以下是关于如何将 Codeforces 的界面语言切换到中文的具体方法: #### 1. 登录账户 用户需要先登录自己的 Codeforces 账户。如果尚未注册账户,则需完成注册流程后再进行操作。 #### 2. 进入个人资料页面 点击右上角用户名旁边的下拉菜单选项,在弹出的列表中选择 **Settings**(设置)。此部分允许用户修改各种偏好设定[^1]。 #### 3. 修改语言选项 在 Settings 页面中找到 **Language** 字段,默认可能是 English 或其他语言。通过下拉框可以选择不同的语言选项,其中包含 Simplified Chinese 表示简体中文。选择后保存更改即可生效[^2]。 #### 4. 验证更改效果 返回至首页或其他任意页面确认网站文字已转换成所选目标语言——即中文环境下的表述形式。此时所有的题目描述、公告以及交互提示都将采用中文呈现给用户阅读理解[^3]。 ```python # 示例代码展示如何模拟简单的语言切换逻辑 class UserPreferences: def __init__(self, username): self.username = username self.language = 'English' def set_language(self, new_lang): supported_languages = ['English', 'Simplified Chinese'] if new_lang in supported_languages: self.language = new_lang print(f"Language switched to {new_lang} for user {self.username}.") else: print("Unsupported language.") user = UserPreferences('example_user') user.set_language('Simplified Chinese') # 切换语言为简体中文 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值