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 & ...
随机推荐
- 经典面试题: 从输入URL到页面加载的过程发生了什么?
可以分为这几个大的过程: DNS解析 TCP连接 客户端发送HTTP请求 服务器处理请求并返回HTTP报文 浏览器解析渲染页面 结束 其中(1)DNS解析可以理解为主寻找这个IP地址的过程,其中如果找 ...
- Unity中的Mono & Linux上编译Mono的流程
前段时间编译了一下Unity的Mono,看了很多相关的文章,也遇到很多新坑.所以来总结一下,加深自己对Mono的理解 为什么Unity可以跨平台运行呢 通常Unity的脚本有C#.JS.Boo.不过现 ...
- Java面试宝典
相关概念 面向对象的三个特征 封装,继承,多态.这个应该是人人皆知.有时候也会加上抽象. 多态的好处 允许不同类对象对同一消息做出响应,即同一消息可以根据发送对象的不同而采用多种不同的行为方式(发送消 ...
- nginx的5个特点
nginx的5个特点(2017/11/16 白杨整理) 1.动静分离 Nginx是一种轻量级,高性能,多进程的Web服务器,非常适合作为静态资源的服务器使用,而动态的访问操作可以使用稳定的Apache ...
- IpHelper根据客户端IP进行网站分流
public class IpHelper { // 核心方法:IP搜索 /// <summary> /// 查找IP所属地区,确保web.c ...
- C#脏字过滤算法
public class DirtyWordOper { private static Dictionary<string, object> hash = new Di ...
- Oracle单行函数基础运用
单行函数 整个SQL的精髓:select语句+单行函数(背) 字符串函数 常用的处理字符串的函数有如下: No. 函数名 含义 1 UPPER(c1) upper 将字符串全部转为大写 2 LOWE ...
- vue-cli——vue-resource登录注册实例
前言 使用vue-resource请求接口非常方便,在使用前需安装vue-resource依赖并在入口文件main.js中声明. 实例功能简述 本实例只有简单的两个模块:登录和注册,主要演示如何用vu ...
- WinForm 窗体之间相互嵌套
public FrmScan() { InitializeComponent(); Form1 frm = new Form1(); frm.Dock = DockStyle.Fill; frm.Fo ...
- 获取request header的值
1Sring mvc 中可以通过注解 : @RequestHeader ("host") String hostName 2httpservletrequest request ...