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)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- VS2015 使用Xunit来进行单元测试
安装Xunit: Xunit的安装现在不需要插件支持了,直接使用NuGet安装如下两个库即可: PM> Install-Package xunit PM> Install-Package ...
- CentOS系统中出现错误--SSH:connect to host centos-py port 22: Connection refused
我在第一次搭建自己的 hadoop2.2.0单节点的伪分布集成环境时遇到了此错误,通过思考问题和查找解决方案最终搞定了这个问题,其错误原因主要有以下几种: 1)SSH服务为安装 此时,采用在线安装的方 ...
- jquery实现抽奖小游戏
在很多网站或游戏活动中我们都会看到有关抽奖的活动或界面: 下面我将给大家介绍下如何通过javascript来实现这样的一个抽奖功能,主要从下面三个步骤入手(文中着重介绍第三部分有关功能的实现): 1. ...
- 非确定性计算引擎转化为C#版本并重构
这是之前我写的原始的 VB.NET 版本: http://www.cnblogs.com/RChen/archive/2010/05/17/1737587.html 转化为 C# 版本后,还进行了一些 ...
- C#中静态和非静态的区别
今天下午面试,HR问道:C#中静态类或静态方法和非静态类静态方法有什么区别?我回答是静态的可以直接调用而非静态的需要实例化.HR说这谁都知道,我问的是本质区别.我当时就郁闷了,我只有8个月的编程经验, ...
- 最近ssh遇到异常及解决
1.SSH框架,spring和struts整合,action中注入service不成功,检测是否缺少 struts2-spring-plugin-2.3.4.1.jar包 2.字符串转 json 加了 ...
- [转载] java多线程学习-java.util.concurrent详解(三)ScheduledThreadPoolExecutor
转载自http://janeky.iteye.com/blog/770441 ------------------------------------------------------------- ...
- (转)从史上八大MySQL宕机事故中学到的经验
一.Percona网站宕机事件 震级:3 发生时长:2011年7月11日 持续时长:数日 地点:加州Pleasanton(幸福屯) 宕机原因:Percona网站主服务器上的3块硬盘损坏,同时因为人员变 ...
- Cngigure和BUS实现远端配置
1 server依赖 <?xml version="1.0" encoding="UTF-8"?><project xmlns="h ...
- flex布局元素操作详情
之前布局一直用的是 position,float之类的,趁着国庆学习一下 flex 布局 父元素: flex-direction: row row-reverse column column-reve ...