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 ...
随机推荐
- hdu 6363 bookshelf
题解讲的很清楚了,直接看代码就懂了 题解:http://bestcoder.hdu.edu.cn/blog/2018-multi-university-training-contest-6-solut ...
- 洛谷 P3434 [POI2006]KRA-The Disks
P3434 [POI2006]KRA-The Disks 题目描述 For his birthday present little Johnny has received from his paren ...
- HDU Victor and World (最短路+状态压缩)
题目链接:传送门 题意: n个城市m条路.刚開始在点1,求把每一个城市都遍历一边最后回到1的花费的最小值. 分析: +n2∗2n). 转自Bestcode. 以下说说我的状态转移,首先 ...
- PipeCAD之管道标准库PipeStd(2)
PipeCAD之管道标准库PipeStd(2) eryar@163.com Key Words. PipeCAD, PipeStd, 管道设计软件,管件库 1. Introduction 管道标准部件 ...
- linux 下的select函数
函数原型 /* According to POSIX.1-2001 */ #include <sys/select.h> //头文件 /* According to earlier st ...
- Linux系统的LOG日志文件及入侵后日志的清除
UNIX网管员主要是靠系统的LOG,来获得入侵的痕迹.当然也有第三方工具记录入侵系统的 痕迹,UNIX系统存放LOG文件,普通位置如下: /usr/adm - 早期版本的UNIX/var/adm - ...
- 开启Windows 7远程桌面功能的做法
作者:朱金灿 来源:http://blog.csdn.net/clever101 本设置方法同样适用用Vista和Windows Server 2008. 1.依次点击"开始"菜单 ...
- js图表插件绘制各种类型图表
官网:http://www.bootcss.com/p/chart.js/ 中文参考手册:http://www.bootcss.com/p/chart.js/docs/ 一.生成折线图 :test.h ...
- 【Django】ORM操作#1
目录 一.介绍 概念 由来 优势 劣势 总结 二.Django中的ORM Django项目使用MySQL Model 快速入门 1. AutoField 2. IntegerField 3. Char ...
- Vim插件使用技巧(转)
在 IDEA Intellij小技巧和插件 一文中简单介绍了一下IdeaVim插件.在这里详细总结一下这个插件在日常编程中的一些常用小技巧.供有兴趣使用这个插件,但对Vim还不十分熟悉的朋友参考.当然 ...