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 > ...
随机推荐
- 阿里巴巴矢量库IconFont__使用小录
使用阿里巴巴矢量库方法虽然不难,但本人记性不好,遂在次记录几笔 阿里巴巴矢量库地址:http://www.iconfont.cn/plus 阿里巴巴矢量库图标好处: 1:图标矢量化 2:自己总结:ic ...
- sql server time(7) 默认值
语句为 ALTER TABLE dbo.YourTable ADD CONSTRAINT DF_TimeDefault DEFAULT '00:00:00' FOR YourTimeColumn 比如 ...
- 【转载】CentOS 安装rz和sz命令 lrzsz
lrzsz在linux里可代替ftp上传和下载.lrzsz 官网入口:http://freecode.com/projects/lrzsz/ lrzsz是一个unix通信套件提供的X,Y,和ZMode ...
- 对 Lua闭包 知识点的学习的总结 ,在这里和大家分享一下,希望对大家有所帮助
Lua闭包 --当一个函数内部嵌套另外一个函数定义时,内部的函数体可以访问外部的函数的局部变量,这种特征为词法定界.--闭包是由函数与其相关的引用环境组合而成的实体 闭包=函数+引用环境--不是在局部 ...
- Linux内核tracepoints
Linux内核tracepoints 简单介绍 内核中的每个tracepoint提供一个钩子来调用probe函数. 一个tracepoint可以打开或关闭.打开时,probe函数关联到tracepoi ...
- List集合中把其中一个元素 调整到集合的第一位
要求:现在想把集合中的某个元素,放到该集合的第一个位置,但是其他元素的顺序不需要管. 方法:需要遍历集合,找到这个元素在集合中的位置,然后使用Collections.swap(list,o,i) (O ...
- 0209利用innobackupex进行简单数据库的备份
利用innobackupex进行简单数据库的备份yum install perl-DBIyum install perl-DBD-MySQLyum install perl-Time-HiResyum ...
- 【ACM】nyoj_143_第几是谁_201308071558
第几是谁?时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 现在有"abcdefghijkl”12个字符,将其按字典序排列,如果给出任意一种排列,我们能说出这个排列 ...
- 1103 N的倍数
1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 一个长度为N的数组A,从A中选出若干个数,使得 ...
- 韩国 DBA 博客
http://mysqldba.tistory.com/ http://cafe.naver.com/mysqlpg http://cafe.naver.com/realmysql http://wi ...