//一个序列,两个公差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. caioj 1071 动态规划入门(二维一边推4:相似基因) (最长公共子序列拓展)

    复制上一题总结 caioj 1069到1071 都是最长公共字序列的拓展,我总结出了一个模型,屡试不爽    (1) 字符串下标从1开始,因为0用来表示字符为空的情况,而不是第一个字符     (2) ...

  2. DATA_PUMP_DIR impdp 指定导出目录

    1.mkdir /tdms1/oracle/dump 2.sqlplus / as sysdba 3.create directory udir as '/tdms1/oracle/dump'; 4. ...

  3. ArcGIS api for javascript——显示地图属性

    描述 本例展示了如哦读取地图和图层的属性和返回信息给用户.本例中的四个按钮允许用户接收地图属性.每个按钮调用不同的函数. ·Get All Map Layers - 这个按钮调用getMapLayer ...

  4. C++模板中重要的术语

  5. ZOJ 1654 Place the Robots (二分匹配 )

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...

  6. python学习之--SyntaxError: Non-ASCII character '\xe5'

    在安装好eclipse之后试了一下 创建了了一个pydev project package.module 在test.py中编写最简单的命令 print "helloworld" ...

  7. 算法导论————EXKMP

    [例题传送门:caioj1461] [EXKMP]最长共同前缀长度 [题意]给出模板串A和子串B,长度分别为lenA和lenB,要求在线性时间内,对于每个A[i](1<=i<=lenA), ...

  8. Win form碎知识点

    判断1.ds不能为空 2.ds的表数量必须大于0 3.判断ds的第一个表中的行数必须有 if (ds.Tables.Count > 0 && ds != null &&a ...

  9. vue 指令的用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 织梦DedeCMS判断简略标题为空时则显示完整标题

    使用织梦DedeCMS系统程序开发网站中,我们会遇到很多因网页版面设计限定的宽度,使文章标题需要进行字数限制,通常做法是在a标签中加入一个title属性,让鼠标放上去的时候显示完整标题.但是标题被剪裁 ...