预处理出每一个数字的左右两边能够整除它的近期的数的位置

OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1880    Accepted Submission(s): 672

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
 
Author
FZUACM
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2015年07月24日 星期五 08时12分15秒
File Name :HDOJ5288.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; typedef long long int LL; const int maxn=100100;
const LL MOD=(LL)(1e9+7); int n;
int a[maxn];
int Left[maxn],Right[maxn];
vector<int> pos[10010]; void init()
{
for(int i=0;i<=10010;i++)
{
pos[i].clear();
}
for(int i=0;i<n;i++)
{
Left[i]=0; Right[i]=n-1;
}
} void pre()
{
for(int i=0;i<n;i++)
{
int x=a[i];
for(int j=x;j<=10000;j+=x)
{
for(int k=0,sz=pos[j].size();k<sz;k++)
{
int z=pos[j][k];
if(z==i) continue;
else if(z<i)
{
Right[z]=min(Right[z],i-1);
}
else if(z>i)
{
Left[z]=max(Left[z],i+1);
}
}
}
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); while(scanf("%d",&n)!=EOF)
{
init();
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
pos[a[i]].push_back(i);
}
pre();
LL ans=0;
for(int i=0;i<n;i++)
{
LL L=i-Left[i]+1LL;
LL R=Right[i]-i+1LL;
ans=(ans+(L*R)%MOD)%MOD;
}
cout<<ans<<endl;
} return 0;
}

HDOJ 5288 OO’s Sequence 水的更多相关文章

  1. 思维题 HDOJ 5288 OO’s Sequence

    题目传送门 /* 定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置, 第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i] ...

  2. HDU 5288 OO’s Sequence 水题

    OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

  3. hdoj 5288 OO’s Sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 //*************头文件区************* #include<ios ...

  4. 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 ...

  5. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  6. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  7. Hdu 5288 OO’s Sequence 2015多小联赛A题

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  8. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  9. 【HDOJ】5288 OO’s Sequence

    二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...

随机推荐

  1. Cocos2d-x开源、跨平台的游戏引擎

    from://http://blog.linguofeng.com/pages/language/c/Cocos2dx.html Cocos2d-x 开源.跨平台的游戏引擎 一.下载 http://c ...

  2. 泛泰A860(高通8064 cpu 1080p) 刷4.4专用中文recovery TWRP2.7.1.2版(三版通刷)

    欢迎关注泛泰非盈利专业第三方开发团队 VegaDevTeam  (本team 由 syhost suky zhaochengw(z大) xuefy(大星星) tenfar(R大师) loogeo cr ...

  3. .NET:一微秒内可能执行多条 DateTime.Now

    出现BUG的上下文 自己写的工作流引擎出现了一点问题,就是因为可能存在一个请求同时流转两个节点(不必深究这个问题),因为每个节点都有一个“进入时间”,引擎的实现将最后一个“进入时间“对应的节点当作了” ...

  4. itunes connect 沙盒帐号地区的问题导致无法进行充值

    项目代理给台湾发行,版本由项目提交appstore,台湾合作伙伴会进行测试.这里遇到一个问题,就是沙盒帐号测试的时候死活提示充值失败,不走正常的充值流程. 后来我分析了原因,主要是由于帐号的App S ...

  5. [Android Pro] 组件化:企业级大型项目必经之路

    cp : https://www.csdn.net/article/2011-02-11/291667 摘要:超过一年以上.活跃开发的项目往往到后期陷入了一些共性的问题: 构建速度慢,往往生成一次最终 ...

  6. 单元测试利器 JUnit 4

    引言 毋庸置疑,程序员要对自己编写的代码负责,您不仅要保证它能通过编译,正常地运行,而且要满足需求和设计预期的效果.单元测试正是验证代码行为是否满足预期的有效手段之一.但不可否认,做测试是件很枯燥无趣 ...

  7. 在 Linux 下用 CMAKE 编译安装 OpenCV 3.2.0

    [安装相关软件和库] 1.安装CMAKE:这里使用apt-get来安装; CMAKE 是一个跨平台编译工具,能够输出各种makefile,和project 文件,指导编译器编译,对CMAKE具体的可以 ...

  8. 使用samba进行共享文件操作步骤

    使用samba进行共享文件操作步骤 1.验证方式 设置用户访问samba server的验证方式,一共有四种验证方式. a. share:用户访问samba server不需要提供用户名和密码,安全性 ...

  9. 奇怪吸引子---ChenLee

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  10. SharePoint 2013 基于表单 Membership 的身份验证

    其实关于SharePoint 2013 表单身份验证网上已经有很多了,比如SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authenticatio ...