题目传送门

 /*
定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置,
第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i], r[i],复杂度O(n*sqrt(a[i]))
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN];
int l[MAXN], r[MAXN];
int pos[]; int main(void) { //HDOJ 5288 OO’s Sequence
//freopen ("1001.in", "r", stdin);
int n;
while (scanf ("%d", &n) == ) {
for (int i=; i<=n; ++i) {
scanf ("%d", &a[i]);
} int ans = ;
memset (pos, , sizeof (pos));
memset (l, , sizeof (l));
for (int i=; i<=n; ++i) {
for (int j=; j<=sqrt (a[i]); ++j) {
if (a[i] % j == ) {
if (pos[j] > l[i]) l[i] = pos[j];
if (pos[a[i]/j] > l[i]) l[i] = pos[a[i]/j];
}
}
pos[a[i]] = i;
}
for (int i=; i<=; ++i) pos[i] = n + ;
for (int i=; i<=n; ++i) r[i] = n + ;
for (int i=n; i>=; --i) {
for (int j=; j<=sqrt (a[i]); ++j) {
if (a[i] % j == ) {
if (pos[j] < r[i]) r[i] = pos[j];
if (pos[a[i]/j] < r[i]) r[i] = pos[a[i]/j];
}
}
pos[a[i]] = i;
}
for (int i=; i<=n; ++i) {
ans = (ans + (r[i] - i) * (i - l[i]) % MOD) % MOD;
}
printf ("%d\n", ans);
} return ;
}

思维题 HDOJ 5288 OO’s Sequence的更多相关文章

  1. HDOJ 5288 OO’s Sequence 水

    预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 13 ...

  2. hdoj 5288 OO’s Sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 //*************头文件区************* #include<ios ...

  3. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  4. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  5. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  6. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. Hdu 5288 OO’s Sequence 2015多小联赛A题

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  9. 【HDOJ】5288 OO’s Sequence

    二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...

随机推荐

  1. [K/3Cloud] 单据转换插件执行顺序

    1.下推事件及顺序 //初始化变量 OnInitVariable(InitVariableEventArgs e) //解析字段映射关系,并构建查询参数.这里可以加入你想要的额外的字段 OnQuery ...

  2. 【Intellij】Intellij Idea 2017创建web项目及tomcat部署实战

    相关软件:Intellij Idea2017.jdk16.tomcat7 Intellij Idea直接安装(可根据需要选择自己设置的安装目录),jdk使用1.6/1.7/1.8都可以,主要是配置好系 ...

  3. 【PowerDesigner】PowerDesigner之CDM、PDM、SQL之间转换

    有关CDM.PDM.SQL之间转换以及不同数据库之间库表Sql的移植,首先要了解的是它们各自的用途.这里就简单的描述一下,不做详细的解释了. CDM:概念数据模型.CDM就是以其自身方式来描述E-R图 ...

  4. openOffice word转pdf,pdf转图片优化版

    之前写了一个版本的,不过代码繁琐而且不好用,效率有些问题.尤其pdf转图片速度太慢.下面是优化版本的代码. spriing_boot 版本信息:2.0.1.RELEASE 1.配置信息: packag ...

  5. Ubuntu 16.04错误:正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/ppa.launchpad.net_t-tujikawa_ppa_ubuntu_dists_xenial_main_i18n_Translatio

    错误: 正在读取软件包列表... 有错误! E: Encountered a section with no Package: header E: Problem with MergeList /va ...

  6. CentOS 7防火墙服务FirewallD指南

    CentOS 7防火墙服务FirewallD指南 作者:chszs,未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 防火墙是一种位于内部网 ...

  7. java 数据结构. 源代码阅读

    Collections工具类里的 Collections.synchronizedList public static <T> List<T> synchronizedList ...

  8. node-V8

    Node是基于V8引擎的,所以我们运行Js文件不会存在问题,下面演示一下: 因为安装Vscode后,会自动添加本路径到path,所以可以用 code yes.js 来执行创建文件 Vscode是基于N ...

  9. Hiho1041 国庆出游 搜索题解

    题目3 : 国庆出游 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描写叙述 小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比較有特色:它共同拥有n座城市(编号1-n): ...

  10. Spring中定时器实现

    在Spring 中使用Quartz,本文介绍Spring3.0以后自主开发的定时任务工具,spring task,可以将它比作一个轻量级的Quartz,而且使用起来很简单,除spring相关的包外不需 ...