HDU5288 OO’s Sequence
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers ai(0<ai<=10000)
Output
Sample Input
1 2 3 4 5
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define LL long long
#define MAXN 100010
using namespace std;
const LL MOD = 1e9 + ;
int a[MAXN];
LL l[MAXN], r[MAXN], pre[MAXN], last[MAXN];
int main() {
int n;
while(~scanf("%d", &n)) {
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
l[i] = , r[i] = n+;
}
memset(pre, , sizeof(pre));
memset(last, , sizeof(last)); for(int i = ; i <= n; ++i) {
for(int j = a[i]; j <= ; j += a[i]) {
//通过这个循环,如果a[i]是之前一个数的因子,一定会在后边遇到
if(pre[j] != && r[pre[j]] == n+) {
//这个数字 j (j = x * a[i])之前已经出现,且右边界是最右端
r[pre[j]] = i;
//这时更新pre[j]的右端, pre[j] 表示的是 j 最后出现的位置
}
}
pre[a[i]] = i; //当前pre[a[i]] 最后出现的位置是 i
} for(int i = n; i > ; --i) {
for(int j = a[i]; j <= ; j += a[i]) {
if(last[j] != && l[last[j]] == ) {
l[last[j]] = i;
}
}
last[a[i]] = i;
}
LL ans = ;
for(int i = ; i <= n; ++i) {
ans = (LL) (ans % MOD + (LL)(((i-l[i])*(r[i]-i)%MOD)%MOD));
ans %= MOD;
}
cout << ans << endl;
}
return ;
}
HDU5288 OO’s Sequence的更多相关文章
- hdu5288 OO’s Sequence 二分 多校联合第一场
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 解题报告 之 HDU5288 OO' s Sequence
解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) ...
- 2015 Multi-University Training Contest 1 - 1001 OO’s Sequence
OO’s Sequence Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Mean: 给定一个数列,让你求所有区间上满足 ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
随机推荐
- 使用spring注解@Controller @Service @Repository简化配置
前言:在web项目中引入spring框架中的配置文件,我们给每一个java bean进行相关配置可以非常安全,便捷的管理我们的bean.那么,问题来了,如果一个项目中所涉及到的java bean十分庞 ...
- thinkphp上传
上传代码 // 缩略图上传 $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = ;// 设置附件上传大小 $upload-> ...
- css3 动画效果 总结 不断完善~~
1.transition 动画过程改变某个css属性的效果 (比如宽高 颜色) 语法 transition: all 所有元素 + ...
- sublime 编译运行C程序
{ "cmd": ["gcc", "${file}", "-o","${file_path}/${file_b ...
- MongoDB C Driver使用教程
MongoDB C Driver使用教程 转载请注明出处http://www.cnblogs.com/oloroso/ 本指南提供简介 MongoDB C 驱动程序. 在 C API 的详细信息,请参 ...
- css3弹性盒模型
一.简介 css3引入了新的盒模型——弹性盒模型,该模型决定一个盒子在其他盒子中的分布方式以及如何处理可用的空间.使用该模型,可以很轻松的创建自适应浏览器窗口的流动布局或自适应字体大小的弹性布局. 目 ...
- asp.net中membership使用oracle数据库(一)
第一步 数据库的准备 使用 oracle 11g的数据库 需要安装好,安装过程中先决条件检查失败的处理:确认server服务已运行 cmd->net share c$=c: 就可以通过 orac ...
- sql之left join、right join、inner join的区别
sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...
- javaWeb开发中的中文编码问题
常规解决乱码问题的方法是: a.把所有的jsp页面的charset设置为UTF-8. b.添加过滤器,在filter内调用request.setCharacterEncoding("ut ...
- cocoaPods 的使用
打开 终端 1. 移除系统自带的 因为该rub已经被和谐了 使用ruby.taobao.org MCJ:~ MCJ$ sudo gem sources -l *** CURRENT SOURCES * ...