HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=5288
题面:
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 985 Accepted Submission(s): 375
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)
5
1 2 3 4 5
23
解题:
仅仅想到从左到右去找近期的不合法点。没想到从右往左找,那么答案就出来了。事实上数据范围那么小,就已经是一种暗示了。能够用数组记录下其最后出现的位置。注意扫的操作,要和记录同一时候进行。注意小心处理1的情况就好。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#define mod 1000000007
#define maxn 100010
#define LL long long
using namespace std;
int t,le[100010],ri[100010],store[100010],pre[100010],tmp,root;
LL ans;
int main()
{
while(~scanf("%d",&t))
{
ans=0;
for(int i=1;i<=t;i++)
scanf("%d",&store[i]);
for(int i=1;i<=t;i++)
pre[i]=0;
for(int i=1;i<=t;i++)
{
tmp=1;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=max(tmp,pre[j]+1);
tmp=max(tmp,pre[store[i]/j]+1);
}
}
le[i]=tmp;
pre[store[i]]=i;
}
for(int i=1;i<=t;i++)
pre[i]=t+1;
for(int i=t;i>=1;i--)
{
tmp=t;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=min(pre[j]-1,tmp);
tmp=min(tmp,pre[store[i]/j]-1);
}
}
ri[i]=tmp;
pre[store[i]]=i;
}
/*for(int i=1;i<=t;i++)
cout<<i<<" "<<le[i]<<" "<<ri[i]<<endl;*/
for(int i=1;i<=t;i++)
{
ans=(ans+1LL*(i-le[i]+1)*(ri[i]-i+1))%mod;
}
printf("%lld\n",ans);
}
return 0;
}
HDU 5288 OO‘s sequence (技巧)的更多相关文章
- 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 ...
- 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 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- 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 ...
- hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...
- hdu 5288 OO’s Sequence 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- hdu 5288 OO’s Sequence(计数)
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- MYSQL触发器在PHP项目中用来做信息备份、恢复和清空
案例:通过PHP后台代码可以将员工的信息删除,将删除的员工信息进行恢复(类似于从回收站中恢复员工信息),并且还可以将已经删除的员工进行清空(类似于清空回复站的功能). 思路:要有一张员工表,还要有一张 ...
- php 文档操作
ftp_mkdir() 函数在 FTP 服务器上建立新目录. 语法 ftp_mkdir(ftp_connection,dir) 参数 描述 ftp_connection 必需.规定要使用的 FTP 连 ...
- c# RSA加密和解密
"); Console.WriteLine(encodeString); string decode = MyRSA.Decrypt(encode ...
- Java并发之线程管理(线程基础知识)
因为书中涵盖的知识点比较全,所以就以书中的目录来学习和记录.当然,学习书中知识的时候自己的思考和实践是最重要的.说到线程,脑子里大概知道是个什么东西,但很多东西都还是懵懵懂懂,这是最可怕的.所以想着细 ...
- Js实现子窗体给父窗体的元素赋值
假设父窗体有一个html标签元素的id为myCollectionWork,现在如果我想在子窗体中给这个元素赋值那么我们可以使用如下JS代码:$("#myCollectionWork" ...
- 软件测试博客日记Day02-11.16日 —— 赵天宇 —— 禅道的使用和配置
禅道 1. 安装 1. 进入禅道的官方下载地址:http://www.zentao.net/download/80053.html 2. 下载禅道开源版本. 3. 正常安装,注意一定要放在根目录下. ...
- vagrant扩容
参考: https://gist.github.com/christopher-hopper/9755310 https://www.madcoder.cn/vagrant-box-resize.ht ...
- Unbuntu16.04安装搜狗拼音输入法
为了让自己的电脑相对安全一些,我安装了ubuntu的物理机 因为要经常输入汉字,我就在unbuntu里面安装了搜狗输入法 1.在搜狗输入法官网下载Linux版本的安装包:http://pinyin.s ...
- android shape 大全 (转)
1. 各属性的配置语法 在项目 res/drawable 文件夹中创建一个以 shape 为根节点的 XML 文件,基本语法如下: <?xml version="1.0" e ...
- 总结HTML5的学习方法大汇总
html5学习方法之技能清单: 必须掌握基本的Web前端开收技术,其中包括:CSS.HTML.DOM.java.Ajax,jquery,Vue,jquery- mobile,zepto等,在掌握这些技 ...