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
 
 
 
 
题意:函数f(l,r)表示区间l,r中,不是区间中其他所有数的倍数的数的个数
 
直接暴力显然是不可以的
 
思路:
1.预处理出1~1e5每一个数的所有因子,O(nsqrt(n))
2.数组l[i],r[i],分别表示从i开始最左能够到达的位置和最右能够达到的位置,使得[l[i],r[i]]中,i不是任何数的倍数
 
 
 
那么现在就是求出l,r的问题了
pos[i]表示i在数组中出现的位置
 
对于a[i],我们枚举a[i]的所有因子,对于每一个因子,我们已经知道这个因子在数组中出现的位置,二分,然后更新l[i],r[i]
 
求出l,r数组后,
对于每一个数a[i],对答案的贡献=(i-l[i]+1)*(r[i]-i+1)
 
就可以了
 
 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector> #define LL long long
#define pb push_back using namespace std; const int maxn=1e5+;
const int mod=1e9+;
const int inf=0x3f3f3f3f; int a[maxn];
int l[maxn];
int r[maxn];
vector <int> di[maxn];
vector <int> pos[maxn]; void pre_init()
{
for(int i=;i<maxn;i++){
for(int j=;j*j<=i;j++){
if(i%j==){
di[i].pb(j);
if(i/j != j)
di[i].pb(i/j);
}
}
}
} void init(int n)
{
for(int i=;i<maxn;i++){
pos[i].clear();
}
} void solve(int ); int main()
{
pre_init(); int n;
while(~scanf("%d",&n)){
init(n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
pos[a[i]].pb(i);
}
solve(n);
}
return ;
} void solve(int n)
{
for(int i=;i<=n;i++){
l[i]=,r[i]=n;
} for(int i=;i<=n;i++){
for(int j=;j<di[a[i]].size();j++){
int k=di[a[i]][j]; int left=,right=pos[k].size()-; if(right<left)
continue; if(pos[k][left]<i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]>=i)
right=mid;
else
left=mid;
}
if(pos[k][right]<i)
l[i]=max(l[i],pos[k][right]+);
else
l[i]=max(l[i],pos[k][left]+);
} left=,right=pos[k].size()-;
if(pos[k][right]>i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]<=i)
left=mid;
else
right=mid;
}
if(pos[k][left]>i)
r[i]=min(r[i],pos[k][left]-);
else
r[i]=min(r[i],pos[k][right]-);
} }
} /*
for(int i=1;i<=n;i++)
printf("%d %d\n",l[i],r[i]);
*/ LL ret=;
for(int i=;i<=n;i++){
ret+=(i-l[i]+)*(r[i]-i+)%mod;
ret=(ret+mod)%mod;
} printf("%I64d\n",ret);
return ;
}
 
 
 
 
 
 
 
 
 
 
 

hdu 5288 OO’s Sequence 枚举+二分的更多相关文章

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

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

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

  3. HDU 5288 OO’s Sequence 水题

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

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

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

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

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

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

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

  7. hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...

  8. hdu 5288 OO’s Sequence(计数)

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

  9. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. 越狱Season 1-Episode 20: Tonight

    Season 1, Episode 20: Tonight -Pope: I want him under 24hour surveillance. surveillance: 监视 保证24小时监视 ...

  2. 英语语法最终珍藏版笔记-18what 从句的小结

    what 从句的小结 1.意思是“所….的事/物”, 相当于the thing(s) that…, that which…, 或those which… 可以用于以下情况: (1) 引导主语从句.如: ...

  3. 黑马程序员——JAVA基础之常用DOS命令和环境变量的配置

    ------- android培训.java培训.期待与您交流! ----------   1.常用dos命令: dir   显示当前文件下目录                             ...

  4. 论文笔记之:Pedestrian Detection aided by Deep Learning Semantic Tasks

    Pedestrian Detection aided by Deep Learning Semantic Tasks CVPR 2015 本文考虑将语义任务(即:行人属性和场景属性)和行人检测相结合, ...

  5. (总结)Linux下使用rsync最快速删除海量文件的方法

    昨天遇到了要在Linux下删除海量文件的情况,需要删除数十万个文件.这个是之前的程序写的日志,增长很快,而且没什么用.这个时候,我们常用的删除命令rm -fr * 就不好用了,因为要等待的时间太长.所 ...

  6. semat内核阿尔法的状态图

  7. #你好Unity3D#Project脚本执行双击资源操作

    Unity的Project里面放了很多游戏资源,比如脚本或者图片.正常情况下我们可以通过鼠标双击来进行打开.假如我现在不想主动双击打开,我想自动打开某个脚本或者图片再或者别的资源怎么办? 如下代码所示 ...

  8. C#Linq中的Union All/Union/Intersect和Top/Bottom和Paging和SqlMethods,skip,take,takewhile,skipwhile,编译查询等

    我们继续讲解LINQ to SQL语句,这篇我们来讨论Union All/Union/Intersect操作和Top/Bottom操作和Paging操作和SqlMethods操作 . Union Al ...

  9. eclipse项目里面的类有时候会莫名其妙出现很多错误

    由于eclipse的编译是基于时间戳的判断机制的.因此当你按build   all的时候有些eclipse认为时间戳没有改变的类不会被编译.因此你可以先clean一下再编译.这个时候eclipse会将 ...

  10. linux ubuntu系统下,adb不是内部命令 (如何才能让adb命令可以使用)

    linux ubuntu系统下,adb不是内部命令 原文地址 linux ubuntu系统下,adb不是内部命令 解决方法: 1.sudo gedit ~/.bashrc 2.将下面的两句加到上面打开 ...