pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288

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
/**
hdu 5288||2015多校联合第一场1001题
题目大意:给定一个区间。找出f(i,j)的和
解题思路:http://blog.sina.com.cn/s/blog_15139f1a10102vnx5.html 和官方题解想的一样
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef __int64 LL;
const int MAXN = 1e5+10;
const LL MOD = 1e9+7;
int a[MAXN],l,r,n;
vector<int> f[10010];
vector<int> vec[10010];
typedef vector<int>::iterator it; int main()
{
for(int i=1; i<=10000; i++)
for(int j=1; j*i<=10000; j++)
f[i*j].push_back(i);
while(~scanf("%d",&n))
{
for(int i=0; i<=10000; i++)
vec[i].clear();
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
vec[a[i]].push_back(i);
}
LL ans=0;
for(int i=1; i<=n; i++)
{
l=1,r=n;
for(it j=f[a[i]].begin(); j!=f[a[i]].end(); j++)
{
if(vec[*j].empty())continue;
it t=lower_bound(vec[*j].begin(),vec[*j].end(),i);
if(t==vec[*j].end())
{
t--;
l=max((*t)+1,l);
continue;
}
if(*t==i)
{
if(t!=vec[*j].begin())
{
t--;
l=max((*t)+1,l);
t++;
}
if(*t==i)t++;
if(t!=vec[*j].end())
r=min((*t)-1,r);
}
else
{
r=min((*t)-1,r);
if(t!=vec[*j].begin())
{
t--;
l=max((*t)+1,l);
}
}
}
ans = (ans + ((long long)(i - l+1) * (r - i+1) % MOD) ) % MOD;
}
printf("%I64d\n",ans);
}
return 0;
}

hdu 5288||2015多校联合第一场1001题的更多相关文章

  1. 2015 多校赛 第一场 1001 (hdu 5288)

    Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l&l ...

  2. hdu5294||2015多校联合第一场1007 最短路+最大流

    http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...

  3. hdu5289 2015多校联合第一场1002 Assignment

    题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 ...

  4. 2015 多校赛 第一场 1007 (hdu 5294)

    总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...

  5. hdu 4869 Turn the pokers (2014多校联合第一场 I)

    Turn the pokers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)

    题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...

  7. HDU 4868 Information Extraction(2014 多校联合第一场 H)

    看到这道题时我的内心是奔溃的,没有了解过HTML,只能靠窝的渣渣英语一点一点翻译啊TT. Information Extraction 题意:(纯手工翻译,有些用词可能在html中不是一样的,还多包涵 ...

  8. HDU 5289 Assignment(多校联合第一场1002)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  9. HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)

    pid=5358">HDU 5358 题意: 求∑​i=1​n​​∑​j=i​n​​(⌊log​2​​S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...

随机推荐

  1. JavaScript sort() 方法详解

    定义和用法 sort() 方法用于对数组的元素进行排序. 语法 arrayObject.sort(sortby) 参数 描述 sortby 可选.规定排序顺序.必须是函数. 返回值 对数组的引用.请注 ...

  2. 定制滚动条样式 webkit

    ::-webkit-scrollbar              { /* 1 */ } ::-webkit-scrollbar-button       { /* 2 */ } ::-webkit- ...

  3. JAVAscript学习笔记 js条件语句 第三节 (原创) 参考js使用表 (2017-09-14 15:55)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. copy11

    方法二 这种方法也比较简单,主要针对你没有.apk包的情况,比如Android原生自带的APP(计算器.通讯录.短信...),可以通过adb 命令. 1,打开APP. 2,执行> adb log ...

  5. H5定位

    百度地图javaScript API 一.在html文件中引入 <script src="http://api.map.baidu.com/api?ak=Uk9tDddYkrQImXw ...

  6. 网页加速特技之 AMP

    据统计,40%的人会放弃使用加载时间超过3秒的网站.对于加载慢的页面我也是没耐心等待的,同类型网站那么多,为什么不选择加载速度更快体验更好的呢.为了解决网页加载慢的问题,Google联合数十家技术机构 ...

  7. C# 4.0 新特性dynamic、可选参数、命名参数等

    1.dynamic ExpandoObject熟悉js的朋友都知道js可以这么写 :   1 var t = new Object(); 2 t.Abc = ‘something’; 3 t.Valu ...

  8. 《天书夜读:从汇编语言到windows内核编程》八 文件操作与注册表操作

    1)Windows运用程序的文件与注册表操作进入R0层之后,都有对应的内核函数实现.在windows内核中,无论打开的是文件.注册表或者设备,都需要使用InitializeObjectAttribut ...

  9. web前端-----第二弹CSS

    web前端之CSS样式 CSS 语法 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. ''' selector { property: value; property: value; ...

  10. 学习cordic算法所得(流水线结构、Verilog标准)

    最近学习cordic算法,并利用FPGA实现,在整个学习过程中,对cordic算法原理.FPGA中流水线设计.Verilog标准有了更加深刻的理解. 首先,cordic算法的基本思想是通过一系列固定的 ...