hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K
(Java/Others)
Total Submission(s): 1080 Accepted Submission(s): 403
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int inf=0x7fffffff;
const int maxn=100000+1000;
const int mod=1000000000+7;
int a[maxn];
long long l[maxn];
long long r[maxn];
int h[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int cur=inf,te;
for(int i=1;i<=n;i++)
{
cur=inf;
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
cur=min(cur,i-h[j]);
te=a[i]/j;
cur=min(cur,i-h[te]);
} }
l[i]=cur;
h[a[i]]=i;
}
for(int i=1;i<=10500;i++)
h[i]=n+1;
for(int i=n;i>0;i--)
{
cur=inf;
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j==0)
{
cur=min(cur,h[j]-i);
te=a[i]/j;
cur=min(cur,h[te]-i);
}
}
h[a[i]]=i;
r[i]=cur;
}
long long ans=0;
for(int i=1;i<=n;i++)
{
ans=(ans+(l[i]*r[i]))%mod;
}
printf("%I64d\n",ans);
}
return 0;
}
hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)的更多相关文章
- 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 [数学]
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 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- 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——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 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
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- Javascript IE 内存释放
一个内存释放的实例 <SCRIPT LANGUAGE="JavaScript"><!--strTest = "1";for ( var i = ...
- Python3.0 操作MySQL数据库执行SQL语句
py3不支持MySQLdb,需要导入pymysql模块 # coding: utf-8 # Team : Quality Management Center # Author:Carson # Dat ...
- 解决webstorm中vue语法没有提示
首先看看webstrom内置的vue插件,打上勾,没有这个选项就要自己去下载插件了 如果插件还是没有语法提示,可以用下面的方法,自己添加语法进去搜索 unknown HTML tag attribut ...
- url编码函数encodeURI和encodeURIComponent
var url = "http://www.wrox.com/illegal value.html#start";encodeURIComponent(url) //" ...
- opencv笔记
加载图像: OpenCV支持图像格式Windows位图(bmp),便携式图像格式(pbm,pgm,ppm)和Sun光栅(sr,ras). Mat image = imread( imageName, ...
- JVM优化(上)
02.我们为什么要对jvm做优化: 1.标准参数:-help-version 2. -X参数(非标) -Xint-Xcomp -Xint : interpreted-Xcomp: complied ...
- 原生javascript实现call、apply和bind的方法
var context = {id: 12}; function fun (name, age) { console.log(this.id, name, age) } bind bind() 方法会 ...
- C++中const与constexpr区别
对于对象来说 const指的是编译期常量和运行时常量,两者并没有区分 constexpr特指编译期常量 对于函数来说 const可以修饰类的成员函数,被修饰的函数在执行期间不会改变对象的值. clas ...
- 1. 垃圾收集简介 - GC参考手册
说明: 在本文中, Garbage Collection 翻译为 “垃圾收集”, garbage collector 翻译为 “垃圾收集器”; 一般认为, 垃圾回收 和 垃圾收集 是同义词. Mino ...
- LeetCode(4)Median of Two Sorted Arrays
题目 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...