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 & ...
随机推荐
- 定制滚动条样式 webkit
::-webkit-scrollbar { /* 1 */ } ::-webkit-scrollbar-button { /* 2 */ } ::-webkit- ...
- sql select case when 语句
有道笔试题: 服务器监控表server_status中,当服务器状态发生server_status变化时数据表中将被插入一条记录,状态0表示停机 1表示正常,用SQL查询Server A 的停机开始 ...
- Cordova使用build命令出错: Could not create the Java Virtual Machine.
这是因为虚拟机内存不足导致的,解决方案如下: _JAVA_OPTIONS=-Xmx512M
- Python连接Oracle数据库
今天使用Python连接数据库,连接没有问题,就是中文显示乱码,网上找了很多解决方案, 最后选择使用这个 #!/usr/bin/env python # -*- coding:utf-8 -*- #A ...
- CLR之委托的揭秘(二)
杂谈 在开始真正的代码之前,分析一下上周的一些工作内容,发现自己在代码上还是有很多小毛病需要纠正和去更改的,首先之前一直疏于文档的整理,几乎很少去写文档,第二对于接口开发过程中缺少一定的严谨性,很多问 ...
- 裴波那契查找详解 - Python实现
裴波那契查找(Fibonacci Search)是利用黄金分割原理实现的查找方法. 斐波那契查找的核心是: 1.当key == a[mid]时,查找成功: 2.当key < a[mid]时,新的 ...
- 程序、计算机程序、java初论
一.程序? 程序一词来自生活,通常指完成某些事情的一种既定方式和过程,可以将程序看成对一系列动作的执行过程的描述. 例如:个人去银行取钱 1.带上存折/银行卡去银行 2.取号排队 3.将存折或储蓄卡递 ...
- Spring4 AOP详解
Spring4 AOP详解 第一章Spring 快速入门并没有对Spring4 的 AOP 做太多的描述,是因为AOP切面编程概念不好理解.所以这章主要从三个方面详解AOP:AOP简介(了解),基于注 ...
- IMDB TOP 250爬虫
这个小学期Python大作业搞了个获取IMDB TOP 250电影全部信息的爬虫.第二次写爬虫,比在暑假集训时写的熟练多了.欢迎大家评论. ''' ************************** ...
- markdown简述
前端开发的工具 编辑器: 1. 轻量级的,依靠插件:sublime:atom(github):vs code(miscrosaft) 2. 集成的:DW:webstorm:hbuild ...