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 ...
随机推荐
- C++内存动态分配
https://www.percona.com/blog/2012/07/05/impact-of-memory-allocators-on-mysql-performance/ https://su ...
- [Nhibernate]体系结构
引言 在项目中也有用到过nhibernate但对nhibernate的认识,也存留在会用的阶段,从没深入的学习过,决定对nhibernate做一个系统的学习. ORM 对象-关系映射(OBJECT/R ...
- 大熊君大话NodeJS之------MongoDB模块(额外篇)
一,开篇分析 这篇属于扩展知识篇,因为在下面的文章中会用到数据库操作,所以今天就来说说它(Mongodb模块). (1),简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为 ...
- PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?
1."自定义"常用快捷键(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> ...
- Oracle 查看某表 被哪些表外键引用
分2步骤: 1. select * from user_constraints e where e.table_name='xxx'; 2. select a.constraint_type,a.ta ...
- App提交Appstore审核流程
原文: https://www.douban.com/note/461351420/ 这是一个app提交到iTunces Connect被拒了4次摸索出来的经验,说多了都是泪,先让我擦擦...好了,话 ...
- React 还是 Vue: 你应该选择哪一个Web前端框架?
学还是要学的,用的多了,也就有更多的认识了,开发中遇到选择的时候也就简单起来了. 本文作者也做了总结: 如果你喜欢用(或希望能够用)模板搭建应用,请使用Vue 如果你喜欢简单和“能用就行”的东西 ...
- T-SQL 语句的优化
SQL调优. 1.索引是数据库调优的最根本的优化方法.聚簇索引.非聚簇索引. 聚簇索引:物理序与索引顺序相同.(只能有一个) 非聚簇索引:物理顺序与索引顺序不相同. 2.调整WHERE 子句中的连接顺 ...
- Hadoop 部署过程中的一些问题与解决方案
环境--> centos7.1 --> jdk1.8 1.JDK卸载与安装 http://blog.csdn.net/czmchen/article/details/41047187 2. ...
- CSS自适应布局(左右固定 中间自适应或者右侧固定 左侧自适应)
经常在工作中或者在面试中会碰到这样的问题,比如我想要个布局 右侧固定宽度 左侧自适应 或者 三列布局 左右固定 中间自适应的问题. 下面我们分别来学习下,当然我也是总结下而已,有如以下方法: 一: 右 ...