hdu5400Arithmetic Sequence
//一个序列,两个公差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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- Unity Camera中心点的偏移
在VR 中,如果镜片的中心轴,和屏幕的中心轴不在一条线上, 就会出现无论如何调节IPD,看到的图像都不清晰,这时候,要修改Camera的投影矩阵, 只需要一句代码就能搞定: Camera.main.p ...
- linux学习之多高并发服务器篇(三)
UDP多播服务器 多播 组播组可以是永久的也可以是临时的.组播组地址中,有一部分由官方分配的,称为永久组播组.永久组播组保持不变的是它的ip地址,组中的成员构成可以发 生变化.永久组播组中成员的数量都 ...
- linux虚拟机拓展大小
http://blog.csdn.net/wutong_login/article/details/40147057?utm_source=tuicool http://www.linuxidc.co ...
- 百度API调用实例
今天依据需求要从百度API中取出一些数据.这些操作包含:将坐标转换成百度坐标.依据转换的百度坐标进行特定的查询. 有需求的收藏下,免得下次手写浪费时间. 涉及到的操作有:JSON格式的字符解析.HTT ...
- 石子合并 (区间DP)
一.试题在一个园形操场的四周摆放N堆石子(N≤100),现要将石子有次序地合并成一堆.规定每次仅仅能选相邻的两堆合并成新的一堆,并将新的一堆的石子数.记为该次合并的得分.编一程序.由文件读入堆数N及每 ...
- C++学习笔记11-面向对象2
1. 仅仅能初始化直接基类 一个类仅仅能初始化自己的直接基类.直接就是在派生列表中指定的类.假设类C 从类B 派生,类B 从类A 派生,则B 是C 的直接基类.尽管每一个C 类对象包括一个A 类部 ...
- vue17 $watch 监听数据变化
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue16 自定义键盘属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- BZOJ 1579 道路升级 Dijkstra
思路: 这道题 不能把所有边都建出来 会MLE的!!! oh gosh 其实不建所有的边 用的时候再调就行了-.(也没啥区别) //By SiriusRen #include <queue> ...
- Android手机使用WIFI及USB建立FTP服务器总结
想必大家经常在PC和Android之间传输文件,并不是每次都会插USB接口进行文件传输,就算是插上USB接口,还是有个问题,那就是Android打开大容量存储模式之后,经常很多软件就会被强制停止使用, ...