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 4398 Template Library Management (最优页面调度算法)
中等偏易题.操作系统理论中的最优页面调度算法,贪心.当需要淘汰某个模版时,淘汰掉当前手中在最远的将来才会被用到(或者以后永远不再用到)的那个. 代码: #include <iostream> ...
- Opencv Mat的三种常用类型简介
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/47683127 本文主要介绍Opencv ...
- FOJ1205 小鼠迷宫问题 (BFD+递推)
FOJ1205 小鼠迷宫问题 (BFD+递推) 小鼠a与小鼠b身处一个m×n的迷宫中,如图所示.每一个方格表示迷宫中的一个房间.这m×n个房间中有一些房间是封闭的,不允许任何人进入.在迷宫中任何位置均 ...
- Spring Cloud学习笔记【六】Hystrix 监控数据聚合 Turbine
上一篇我们介绍了使用 Hystrix Dashboard 来展示 Hystrix 用于熔断的各项度量指标.通过 Hystrix Dashboard,我们可以方便的查看服务实例的综合情况,比如:服务调用 ...
- javaweb——登陆权限过滤器的编写
http://blog.csdn.net/lzc4869/article/details/50935858
- scala细节
在高版本中,scala使用了自己的String,而不是java.lang.String 字符串转数字:"33.4".toDouble "33.4".toF ...
- Codeforces Round #313 C. Gerald's Hexagon(放三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- PHP长整型在32位系统中强制转化溢出
CleverCode近期遇到一个PHP项目整形转化问题,mysql有一个字段id是bigint的,里面有长整型,如id = 5147486396.可是php代码因为历史原因却部署在多台机器中,当中A机 ...
- HBase的单节点集群详细启动步骤(分为Zookeeper自带还是外装)
伪分布模式下,如(weekend110)hbase-env.sh配置文档中的HBASE_MANAGES_ZK的默认值是true,它表示HBase使用自身自带的Zookeeper实例.但是,该实例只能为 ...
- js创建dom操作select
document.getElementById("column-left").getElementsByTagName("header")[0].onclick ...