2015 多校赛 第一场 1001 (hdu 5288)
Description
Input
In each test case:
First line: an integer n(n<=10^5) indicating the size of array
Second line:contain n numbers a i(0<a i<=10000)
Output
Sample Input
1 2 3 4 5
Sample Output
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=,maxx=;
const long long mod=;
vector<int>divi[maxn];
int a[maxx],l[maxx],r[maxx],pos[maxn],n;
void ini(){
for(int i=;i<=;i++)
for(int j=;j<=i;j++)
if(i%j==) divi[i].push_back(j);
//预处理出10000内所有数的因子
}
int main(){
ini();
while(~scanf("%d",&n)){
for(int i=;i<n;i++)
scanf("%d",&a[i]);
memset(l,-,sizeof(l));
memset(r,0x3f,sizeof(r));
memset(pos,-,sizeof(pos));
//l[i]表示a[i]左边与之最接近的它的因子的下标
for(int i=;i<n;i++){
int lef=-;
for(int j=;j<divi[a[i]].size();j++)
lef=max(lef,pos[divi[a[i]][j]]);
pos[a[i]]=i;
//pos数组用于更新维护最靠近a[i]的因子数的下标
l[i]=lef;
}
memset(pos,0x3f,sizeof(pos));
//r[i]表示a[i]右边与之最接近的它的因子的下标
for(int i=n-;i>=;i--){
int rig=0x3f3f3f3f;
for(int j=;j<divi[a[i]].size();j++)
rig=min(rig,pos[divi[a[i]][j]]);
pos[a[i]]=i;
//pos数组用于更新维护最靠近a[i]的因子数的下标
r[i]=rig;
}
long long ans=,L,R;
for(int i=;i<n;i++){
if(l[i]==-) L=i+;
//若为原值,则说明a[i]左边不存在因子
else L=i-l[i];
//否则,令L为a[i]到其因子右边第一个数之间的个数
if(r[i]==0x3f3f3f3f) R=n-i;
else R=r[i]-i;
ans=(L*R%mod+ans)%mod;
//L*R为包含a[i]的连续区间的组合数。
}
printf("%d\n",ans);
}
return ;
}
2015 多校赛 第一场 1001 (hdu 5288)的更多相关文章
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- 2015 多校赛 第一场 1002 (hdu 5289)
Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- 2015 多校赛 第二场 1006 (hdu 5305)
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
- 2015 多校赛 第二场 1004 hdu(5303)
Problem Description There are n apple trees planted along a cyclic road, which is L metres long. You ...
- 2015 多校赛 第二场 1002 (hdu 5301)
Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...
- HDU6578 2019HDU多校训练赛第一场 1001 (dp)
HDU6578 2019HDU多校训练赛第一场 1001 (dp) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题意: 你有n个空需要去填,有 ...
- hdu5294||2015多校联合第一场1007 最短路+最大流
http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...
- 2019牛客多校赛第一场 补题 I题
I题 Points Division 题意: 给你n个点,每个点有坐标(xi,yi)和属性(ai,bi),将点集划分为两个集合, 任意 A 集合的点 i 和 B 集合点 j, 不允许 xi > ...
随机推荐
- 安装rails卡住很慢 出现302 Moved Temporarily
在MAC上安装rails的时候,使用命令$ gem install rails 发现一直没响应,使用$ gem install rails-V命令发现,安装会在中间卡住,出现302 Moved Tem ...
- AI:PR的数学表示-传统方法PR
前言: 接上一篇:AI:模式识别的数学表示 在图像处理PR领域,相对于ANN方法,其他的方法一般称为传统方法.在结构上,几乎所有的PR方法都是可解释的.且任一传统方法,在一定约束下,可以转换为SV近邻 ...
- js 立即调用函数
function makeCounter() { //不能立即执行 // 只能在makeCounter内部访问i var i = 0; return function () { console.log ...
- MySQL--增删改查分页存储过程以及事务
添加和修改写在一起了 可以用id判断添加和修改 和事务在一起编码 可以让代码更严谨 在这里简单的说一下事务的四大特性 事务四大特性之原子性:原子性是指事务是一个不可再分割的工作单位,事务中的操作要么都 ...
- 记Python学习
上周学的Python,感觉有点忘了,现在回顾一下... 一.Python安装及测试:https://www.cnblogs.com/weven/p/7252917.html 例子: Python自带的 ...
- HDU 2267 How Many People Can Survive(广搜,简单)
题目 //一道简单的广搜水题 #include<queue> #include<stdio.h> #include<string.h> #include<al ...
- mysql字符集和排序规则
1.关于字符集和排序规则所为字符集,就是用来定义字符在数据库中的编码的集合.常见的字符集有:utf8(支持中文)和AccIS(不支持中文) 数据库中的排序规则用来定义字符在进行排序和比较的时候的一种规 ...
- Mybatis配置之别名配置元素详述
这里我们贴出之前的UserDao对应的mapper文件,如下所示 从这个配置文件中,我们可以看到<select>.<insert>和<update>三个标签元素的r ...
- 最佳实践 | 源码升级gcc
1.下载升级包所需软件 boost_1_60_0.tar.gz http://www.boost.org/users/history/version_1_60_0.html gcc-4.8.0.tar ...
- python打印日历
#未优化的代码 1 #输出日历 def print_calendar(year,month,date = 1): month_dict = {':'July', ':'December'} #数字月份 ...