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 ...
随机推荐
- Java 文件上传至leanCloud
首先,在Controller端入参设置为 @RequestParam(value = "file",defaultValue = "") MultipartFi ...
- 搭建基于MinGW平台的《OpenGL蓝皮书(OpenGL SuperBibe 5th)》示例代码编译环境
副标题:搭建基于MinGW平台的<OpenGL超级宝典>(OpenGL蓝皮书第5版)GLTools 编译环境.示例代码:Triangle.cpp @ SB5.zip 以下内容以及方法均参考 ...
- 数据库处理session类
<?php /* * 使用数据库处理session * php.ini 中 session.save_handler 设为 "user" */ class Dbsession ...
- cinder侧挂载卷流程分析
cinder侧挂载卷流程分析,存储类型以lvm+iscsi的方式为分析基础cinder侧主要调用了三个接口1)reserve_volume: 把volume的状态改为attaching,阻止其它节点执 ...
- 使用jmeter做简单的场景设计
使用jmeter做简单的场景设计 Jmeter: Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试.我之所以选择它,最重要的一点就是----开源 个人 ...
- 【大数据系统架构师】0.2 Linux基础
1. Linux基本环境 1.1 大数据Hadoop前置大纲讲解 1)Linux系统,基本命令 2)Java语言,JavaSE相关知识 3)MySQL基本的DML和DDL 1.2 常见Linux系统. ...
- 查看服务器的ip地址
因测试需要查看服务器的ip地址,故进行搜索. 1.(操作成功的方法)在浏览器输入www.ip.cn,可查询出ip地址: 2.(说明书的操作方法,但我未能查询到ip地址)在浏览器输入http://ip. ...
- win10 + Lubuntu 双系统安装
win10 + Lubuntu 双系统安装 最近重装了系统,索性直接安装win10 + Lubuntu 双系统,便于在物理机下进行 Linux开发. 这里我选择的 Linux 发行版是 Lubuntu ...
- 洛谷P1963 [NOI2009]变换序列(二分图)
传送门 我可能真的只会网络流……二分图的题一点都做不来…… 首先每个位置有两种取值,所以建一个二分图,只要有完美匹配就说明有解 考虑一下每一个位置,分别让它选择两种取值,如果都不能形成完美匹配,说明无 ...
- 【微服务】之七:轻松搞定SpringCloud微服务-API权限控制
权限控制,是一个系统当中必须的重要功能.张三只能访问输入张三的特定功能,李四不能访问属于赵六的特定菜单.这就要求对整个体系做一个完善的权限控制体系.该体系应该具备针区分用户.权限.角色等各种必须的功能 ...