hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288
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
/**
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题的更多相关文章
- 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 ...
- hdu5294||2015多校联合第一场1007 最短路+最大流
http://acm.hdu.edu.cn/showproblem.php? pid=5294 Problem Description Innocent Wu follows Dumb Zhang i ...
- hdu5289 2015多校联合第一场1002 Assignment
题意:给出一个数列.问当中存在多少连续子区间,当中子区间的(最大值-最小值)<k 思路:设dp[i]为从区间1到i满足题意条件的解.终于解即为dp[n]. 此外 如果对于arr[i] 往左遍历 ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- hdu 4869 Turn the pokers (2014多校联合第一场 I)
Turn the pokers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4865 Peter's Hobby(2014 多校联合第一场 E)(概率dp)
题意:已知昨天天气与今天天气状况的概率关系(wePro),和今天天气状态和叶子湿度的概率关系(lePro)第一天为sunny 概率为 0.63,cloudy 概率 0.17,rainny 概率 0.2 ...
- HDU 4868 Information Extraction(2014 多校联合第一场 H)
看到这道题时我的内心是奔溃的,没有了解过HTML,只能靠窝的渣渣英语一点一点翻译啊TT. Information Extraction 题意:(纯手工翻译,有些用词可能在html中不是一样的,还多包涵 ...
- HDU 5289 Assignment(多校联合第一场1002)
Assignment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
pid=5358">HDU 5358 题意: 求∑i=1n∑j=in(⌊log2S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...
随机推荐
- Problem B: 点之间的距离
#include <iostream> #include <vector> #include <cmath> #include <algorithm> ...
- Git Submodules are not SVN Externals
一直在寻找Git跟TFS里面类似SVN Externals的替代方案, 今天终于找到了GIT里面的替代方案,在此做个备注 http://alexking.org/blog/2012/03/05/git ...
- eclipse安装checkstyle无法加载到preferences的问题
描述一下问题,eclipse安装checkstyle,不管是在线安装还是下载安装,在preferences都没有checkstyle选项,如下: 然我们要的效果是这样的: 解决方案如下: 1 启动 ...
- python 有关datetime时间日期 以及时间戳转换
直接上代码 其中有注释 #coding=utf-8 import time import datetime def yes_time(): #获取当前时间 now_time = datetime.da ...
- node.js安装——Windows7系统下的安装及其环境部署——特别详细
作为一个前端的菜鸟同学,之间也没学过什么框架,目前公司做项目,所用到的webpack+node.js+vue. 首先,关于node的环境部署方面,建议官网安装node.js,最好不要安装非稳定版的版本 ...
- iOS获取所有机型
1.手机系统版本:9.1 NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 2.手机类型:iPhone 6 NSSt ...
- TCP:传输控制协议
概述: 书中采用了8章来介绍TCP,可见其重要性.TCP是一种面向连接的.可靠的字节流服务,也就是说两方要交换数据必须先建立一个连接. TCP的信息单位称为segment.TCP对字节流的内容不作任何 ...
- linux如何在日志中查找关键字、前几行、结尾几行
如何使用命令行快速查看项目日志是每个开发人员必备技能,尤其在没有专门日志搜集系统的情况下,想要知道目前项目运行状态最好的办法就是打开log日志一瞅即明白. 复杂的到用时再查不晚,但是简单的还是有必要掌 ...
- spring boot 错误,求大神帮解决
Exception in thread "main" java.lang.IllegalStateException: Failed to read Class-Path attr ...
- 如何使用MFC连接Access数据库
(1)新建一个Access数据库文件.将其命名为data.mdb,并创建好表.字段. (2)为系统添加数据源.打开“控制面板”—>“管理工具”—>“数据源”,选择“系统DSN”,点击右边的 ...