//一个序列,两个公差d1,d2
//问有多少个区间使得这个区间存在一个点,它的左边是公差为d1的序列
//它的右边是公差为d2的序列
//直接存入每一个点向左和向右延伸的公差长度,乘一下即可
//还有就是注意一下d1=d2的情况
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 1e5+10 ;
int a[maxn] ;
typedef long long ll ;
ll l[maxn] , r[maxn] ;
int main()
{
int n , d1 , d2 ;
while(~scanf("%d%d%d" ,&n , &d1 , &d2))
{
for(int i = 1;i <= n;i++)
scanf("%d" , &a[i]) ;
ll ans = 0 ;
if(d1 == d2)
{
ll sum = 1;
for(int i = 2;i <= n;i++)
if(a[i] == a[i-1] + d1)
sum++ ;
else
{
ans += (sum+1)*sum/2 ;
sum = 1 ;
}
ans += (sum+1)*sum/2 ;
}
else
{
l[0] = 0 ;r[n+1] = 0 ;
for(int i = 1;i <= n;i++)
if(a[i] == a[i-1] + d1)
l[i] = l[i-1] + 1 ;
else l[i] = 1 ;
for(int i = n;i >= 1;i--)
if(a[i] == a[i+1] - d2)
r[i] = r[i+1] + 1 ;
else r[i] = 1 ;
for(int i = 1;i <= n;i++)
ans += l[i]*r[i] ;
}
printf("%lld\n" , ans) ;
}
return 0 ;
}

hdu5400Arithmetic Sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. MAC下搭建appium UI自动化环境

    参考资料: http://qa.blog.163.com/blog/static/190147002201510161119832/ http://blog.csdn.net/liuchunming0 ...

  2. Zookeeper入门:基本概念、5项配置、启动

    起源 最早接触Zookeeper,是在学习Hadoop权威指南这本书的时候,印象中是Hadoop项目的一个子工程.      最近,项目中需要用到"分布式锁".      之前,在 ...

  3. XML和Schema命名空间详解

    来源:https://blog.csdn.net/wanghuan203/article/details/9204337 XML和Schema具有无关平台,技术厂商,简单,规范统一等特点,极具开放性, ...

  4. ECNUOJ 2619 询问

    询问 Time Limit:2000MS Memory Limit:65536KBTotal Submit:286 Accepted:70 Description  Pollux最近对字符串匹配很感兴 ...

  5. 洛谷 P1769 淘汰赛制_NOI导刊2010提高(01)

    P1769 淘汰赛制_NOI导刊2010提高(01) 题目描述 淘汰赛制是一种极其残酷的比赛制度.2n名选手分别标号1,2,3,…,2^n-1,2^n,他们将要参加n轮的激烈角逐.每一轮中,将所有参加 ...

  6. HBase 1.1.2 优化插入 Region预分配

    预分Region 与 不预分Region 的测试: 1 不预分Region:       23~29秒插入100W数据   并且蛋疼的是每次都写入一个 RegionServer 且  只在一个 Reg ...

  7. 动态网页爬取样例(WebCollector+selenium+phantomjs)

    目标:动态网页爬取 说明:这里的动态网页指几种可能:1)须要用户交互,如常见的登录操作:2)网页通过JS / AJAX动态生成.如一个html里有<div id="test" ...

  8. Rapidjson的简单使用示例

    很早就想用用Markdown了,一直没机会.今天就来试一下 先放个目录: Rapidjson的简单使用示例 rapidjson官方教程 本示例所用环境 示例代码与注释 rapidjson官方教程 如果 ...

  9. Spring MVC 注解式

    1.注解式控制器简介 一.Spring2.5之前,我们都是通过实现Controller接口或其实现来定义我们的处理器类.已经@Deprecated.   二.Spring2.5引入注解式处理器支持,通 ...

  10. NGINX 代理以及 HTTPS (一)

    一. Nginx 安装 和基础代理配置 假如 启动nginx 出现这个错误,可能是 iis服务被打开了,80端口被占用了. 需要如下操作: 用Nginx 配置一个test.com 的代理名称.配置ho ...