题意:http://acm.hdu.edu.cn/showproblem.php?pid=5400

思路:预处理出每个点向左和向右的最远边界,从左向右枚举中间点,把区间答案加到总答案里面。由与可能与前面的区间重叠,需要减去重复的答案,由于左边界非降,所以重叠的区间长度很容易得到。

#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull; //#ifndef ONLINE_JUDGE
void RI(vector<int>&a,int n){a.resize(n);for(int i=;i<n;i++)scanf("%d",&a[i]);}
void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>
void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?:-;
while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
//#endif
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);} const double PI = acos(-1.0);
const int INF = 1e9 + ;
const double EPS = 1e-12; /* -------------------------------------------------------------------------------- */ const int maxn = 1e5 + ; int a[maxn], R[maxn], L[maxn]; int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int n, d1, d2;
while (cin >> n >> d1 >> d2) {
for (int i = ; i <= n; i ++) {
scanf("%d", a + i);
}
for (int i = n; i >= ; i --) {
a[i] = a[i] - a[i - ];
}
a[n + ] = INF * ;
R[n + ] = INF;
for (int i = ; i <= n; i ++) {
L[i] = max(, a[i] == d1? L[i - ] : i);
}
for (int i = n; i; i --) {
R[i] = min(n, a[i + ] == d2? R[i + ] : i);
}
int lastl = , lastr =;
ll ans = ;
for (int i = ; i <= n; i ++) {
ll c = R[i] - L[i] + ;
ans += c * (c + ) / ;
ll cc = min(lastr, R[i]) - L[i] + ;
if (cc > ) ans -= cc * (cc + ) / ;
lastl = L[i];
umax(lastr, R[i]);
}
cout << ans << endl;
}
return ;
}

[hdu5400 Arithmetic Sequence]预处理,容斥的更多相关文章

  1. HDU5400 Arithmetic Sequence

    解题思路:这题看懂题目是很关键的,这个区间是等差数列,且公差为d1或d2, 特别注意单个数字也为等差数列.每次求出等差数列序列长度,然后   求出对应这种长度对应有多少种组合方式,累加起来就是结果. ...

  2. HDU 4675 GCD of Sequence(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给出n,m,K,一个长度为n的数列A(1<=A[i]<=m).对于d(1< ...

  3. HDU 5297 Y sequence 容斥 迭代

    Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...

  4. HDU - 5297:Y sequence (迭代&容斥)

    Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...

  5. hdu4390-Number Sequence(容斥计算)

    题意:给定b数列.计算有多少种数列 a1,a2,...,an 满足条件 a1*a2*...*an=b1*b2*-*bn (ai>1). 解法:处理出b数列中出现的全部质因子的数量记录在map中, ...

  6. HDU 5838 (状压DP+容斥)

    Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...

  7. XTU 1242 Yada Number 容斥

    Yada Number Problem Description: Every positive integer can be expressed by multiplication of prime ...

  8. 青云的机房组网方案(简单+普通+困难)(虚树+树形DP+容斥)

    题目链接 1.对于简单的版本n<=500, ai<=50 直接暴力枚举两个点x,y,dfs求x与y的距离. 2.对于普通难度n<=10000,ai<=500 普通难度解法挺多 ...

  9. hdu 5400 Arithmetic Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...

随机推荐

  1. 常用ElasticSearch 查询语句

    为了演示不同类型的 ElasticSearch 的查询,我们将使用书文档信息的集合(有以下字段:title(标题), authors(作者), summary(摘要), publish_date(发布 ...

  2. bypass安全狗测试学习

    搭建简单的sql注入环境 在test数据库中创建sqltest表,插入字段数据 编写存在注入的php文件 <?php $id = $_REQUEST['uid']; echo "您当前 ...

  3. samba 客户端工具 smbclient和samba挂载到本地

    smbclient命令属于samba套件,它提供一种命令行使用交互式方式访问samba服务器的共享资源. 安装 yum install -y samba-client 常用参数 -c<命令> ...

  4. HTTPie:替代 Curl 和 Wget 的现代 HTTP 命令行客户端

    HTTPie 工具是现代的 HTTP 命令行客户端,它能通过命令行界面与 Web 服务进行交互. -- Magesh Maruthamuthu 大多数时间我们会使用 curl 命令或是 wget 命令 ...

  5. PHP入门-1

    基本数据类型: 1.整形 2.浮点型 3.字符串 4.布尔型 5.数组和对象 6.null 7.资源类型 8.伪类型 由于php是弱语言,所以他的数据类型不用自己来定义.定义一个数据类型,$name ...

  6. 2019-2020-1 20199329《Linux内核原理与分析》第七周作业

    <Linux内核原理与分析>第七周作业 一.本周内容概述: 对Linux系统如何创建一个新进程进行追踪 分析Linux内核创建一个新进程的过程 二.本周学习内容: 1.学习进程的描述 操作 ...

  7. cocos2d 导演,场景

    导演(Director) Cocos2d-x 使用导演的概念,这个导演和电影制作过程中的导演一样!导演控制电影制作流程,指导团队完成各项任务.在使用 Cocos2d-x 开发游戏的过程中,你可以认为自 ...

  8. 日志分析工具ELK(四)

    Logstash收集TCP日志 #Input plugins TCP插件 所需的配置选项 tcp { port =>... } [root@linux-node1 ~]# cat tcp.con ...

  9. js基石之---易读、易复用、易重构的 JavaScript 代码规范

    易读.易复用.易重构的 JavaScript 代码规范 1.变量命名规范有意义 Bad: const yyyymmdstr = moment().format("YYYY/MM/DD&quo ...

  10. 解决 docker.io 上拉取 images Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout

    处理方式 使用如下命令获取 registry-1.docker.io 可用的 ip dig @114.114.114.114 registry-1.docker.io 看到如下输出结果 ; <& ...