HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1549 Accepted Submission(s): 559
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)
题目大意:给你一个长度为n的区间。求这个区间内任意子区间中ai没有因子的ai的个数。
解题思路:从左往右遍历a数组得到L数组。对于ai,枚举j 1-->sqrt(ai),如果j是ai的约数并且j已经在ai之前,那么我用max取离i最近的位置;相应的ai/j也是ai的约数,同理如果ai/j也在ai之前,也用max取离i最近的位置。对于R数组,同理可得。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
const int maxn=1e5+20;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
int a[maxn],L[maxn],R[maxn];
int pos[maxn];
int main(){
int n,limj;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
memset(pos,0,sizeof(pos));
for(int i=1;i<=n;i++){
L[i]=0;
limj=(int)sqrt(a[i]);
for(int j=1;j<=limj;j++){
if(a[i]%j==0){
if(pos[j]){
L[i]=max(L[i],pos[j]);
}
if(pos[a[i]/j]){
L[i]=max(L[i],pos[a[i]/j]);
}
}
}
pos[a[i]]=i;
}
memset(pos,0,sizeof(pos));
for(int i=n;i>=1;i--){
R[i]=n+1;
limj=(int)sqrt(a[i]);
for(int j=1;j<=limj;j++){
if(a[i]%j==0){
if(pos[j]){
R[i]=min(R[i],pos[j]);
}
if(pos[a[i]/j]){
R[i]=min(R[i],pos[a[i]/j]);
}
}
}
pos[a[i]]=i;
}
int sum=0,res;
for(int i=1;i<=n;i++){
sum=(sum%MOD+((i-L[i])*(R[i]-i))%MOD)%MOD;
}
printf("%d\n",sum);
}
return 0;
}
HDU 5288——OO’s Sequence——————【技巧题】的更多相关文章
- 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 [数学]
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 (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 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
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的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 ...
随机推荐
- delegate Func Action Expression
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; na ...
- 分享我的第一个asp.net core开发过程
.net core 这个东西感觉还是很不错的,学习了一下,并且做了一个微服务(IP地址查询服务) http://vju.cc/ip/ipquery 看上他的跨平台功能,所以就研究一下,中间有不少坑,有 ...
- MS SQL Server计算间隔时间
开始需要,写了一个计算时间间隔的函数,可以参考: 得到的结果: 再列举一个例子:
- 教你如何选择BI数据可视化工具
本文来自网易云社区. 关于如何选择BI数据可视化工具,总体而言,主流BI产品在选择的时候要除了需要考虑从数据到展现.从公司内到公司外等各种场景,结合前面朋友的回答,还需要考虑以下几点:1:以后的数据处 ...
- 「BZOJ 5188」「Usaco2018 Jan」MooTube
题目链接 luogu bzoj \(Describe\) 有一个\(n\)个节点的树,边有权值,定义两个节点之间的距离为两点之间的路径上的最小边权 给你\(Q\)个询问,问你与点\(v\)的距离大于等 ...
- JDBC_ResultSet结果集用法_游标原理_关闭连接问题
依次关闭使用对象及连接 ResultSet---Statement--Connectionimport java.sql.Connection;import java.sql.DriverManage ...
- zbar
源码下载链接:http://sourceforge.net/projects/zbar
- flex弹性布局,好用
一直不太喜欢自己布局前端页面,都是扒别人的页面 ,最近在练习小程序,页面无处可扒,只有自己布局 发现flex弹性布局真好用,布局起来很简单,实现的效果也很好,赞 以后可以自己写一点前端了,哈哈
- springcloud微服务总结五 服务熔断
一:雪崩效应 如下图所示:A作为服务提供者,B为A的服务消费者,C和D是B的服务消费者.A不可用引起了B的不可用,并将不可用像滚雪球一样放大到C和D时,导致整个系统瘫痪,雪崩效应就形成了. 雪崩过程: ...
- angluarJs与后台交互小案例
.myService.html: <!DOCTYPE HTML> <html ng-app="app"> <head> <title> ...