题目链接: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

Problem Description
OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know

∑i=1n∑j=inf(i,j) mod (109+7).

 
Input
There are multiple test cases. Please process till EOF.

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)
 
Output
For each tests: ouput a line contain a number ans.
 
Sample Input
5
1 2 3 4 5
 
Sample Output
23
 
Author
FZUACM
 
Source
 

解题:

仅仅想到从左到右去找近期的不合法点。没想到从右往左找,那么答案就出来了。事实上数据范围那么小,就已经是一种暗示了。能够用数组记录下其最后出现的位置。注意扫的操作,要和记录同一时候进行。注意小心处理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 (技巧)的更多相关文章

  1. 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 ...

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

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

  3. HDU 5288 OO’s Sequence 水题

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

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

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

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

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

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. npm常用命令及版本号浅析

    npm 包管理器的常用命令 测试环境为node>=8.1.3&&npm>=5.0.3 1, 首先是安装命令 //全局安装 npm install 模块名 -g //本地安装 ...

  2. JS中有关正则表达式的一些常见应用

    总所周知,正则表达式主要用于字符串处理.表单验证等,简单的代码量实现复杂的功能 1.身份证号码的一个校验 先做一个简单的位数校验来判断身份证的合法性:(15位数字或18位数字或17位数字加X|x) v ...

  3. RabbitMQ的简单应用

    虽然后台使用了读写分离技术,能够在一定程度上抗击高并发,但是如果并发量特别巨大时,主数据库不能同时处理高并发的请求,这时数据库容易宕机. 问题: 现在的问题是如何既能保证数据库正常运行,又能实现用户数 ...

  4. [转载] Rss 与 Feed 的概念区别

    转载自http://www.chinaz.com/news/2011/0831/207961.shtml 可能很多刚刚接触博客的童鞋们,也和我一样不太了解:rss和feed概念或者说不了解rss和fe ...

  5. Python 日志处理(一) 按Nginx log_format 分割日志记录

    要求:不使用正则 根据nginx 默认的日志记录格式,分割日志记录. log_format main '$remote_addr - $remote_user [$time_local] " ...

  6. [欧拉路径]Play on Words UVA10129

    传送门:   UVA - 10129 题目大意: 给定一些单词(可能会重复出现),判断单词是否能排成一个序列,前提是单词的最后一个字母与下一个单词的第一个字母相同.输出"The door c ...

  7. 查看.ssh文件在哪

    输入命令 ll -d ~/.ssh 后你就都明白了.

  8. OC语言的面向对象—类和对象、方法

    1. 面向对象和面向过程思想 OC是面向对象的,C是面向过程的.面向对象和面向过程只是解决问题的两种不同思想 1. 面向对象和面向过程的区别 1) 以用电脑听歌为例子 a) 面向过程 ➢ 打开电脑 ➢ ...

  9. 【javaFX学习】(一) 建一个简单的界面

    转载注明出处:http://www.cnblogs.com/lensener/p/7976953.html 用过swing都知道有多蛋疼,界面有多丑.自从用了javaFX,腰也不酸了,腿也不疼了. 废 ...

  10. Servlet中web.xml 以及 <url-pattern>总结

    web.xml中添加Servlet配置信息 使用Eclipse创建Servlet,会自动的在WEB-INF下的web.xml中声明,但是有的时候需要我们手动的写入配置信息,以下就是Servlet在we ...