HDU 5288 OO’s Sequence 水题
OO’s Sequence
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5288
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
Hint
题意
f(l,r)表示[l,r]区间中有多少个i满足在这个区间中找不到其他j使得ai%aj=0
然后让你输出所有f(l,r)的累加。
题解:
对于每一个位置,我算贡献就好了。
直接暴力分解a[i]就好了。
复杂度nsqrtn的。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
const int mod = 1e9+7;
int a[maxn],n;
int L[maxn],R[maxn];
int p[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(L,0,sizeof(L));
memset(R,0,sizeof(R));
memset(p,0,sizeof(p));
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=sqrt(a[i]);j++)
if(a[i]%j==0)L[i]=max(L[i],p[j]+1),L[i]=max(L[i],p[a[i]/j]+1);
p[a[i]]=i;
}
reverse(a+1,a+1+n);
memset(p,0,sizeof(p));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=sqrt(a[i]);j++)
if(a[i]%j==0)R[i]=max(R[i],p[j]+1),R[i]=max(R[i],p[a[i]/j]+1);
p[a[i]]=i;
}
long long ans = 0;
for(int i=1;i<=n;i++)
{
ans += 1ll*(i-L[i]+1)*(n-R[n-i+1]+1-i+1);
ans%=mod;
//cout<<L[i]<<" "<<n-R[i]+1<<endl;
}
cout<<ans<<endl;
}
}
HDU 5288 OO’s Sequence 水题的更多相关文章
- 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 ...
- HDU 5288——OO’s Sequence——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 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 ...
- 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 ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- arping详解
arping干嘛用的? arping主要干的活就是查看ip的MAC地址及IP占用的问题. 参数 -0:指定源地址为0.0.0.0,这个一般是在我们刚刚安装好系统,电脑还没配置好IP的时候 -a:Aud ...
- wait与waitpid
1. 函数原型: #include <sys/wait.h> pid_t wait(int *statloc); pid_t waitpid(pid_t pid, int *statloc ...
- Linux内核通知链机制的原理及实现【转】
转自:http://www.cnblogs.com/armlinux/archive/2011/11/11/2396781.html 一.概念: 大多数内核子系统都是相互独立的,因此某个子系统可能对其 ...
- libsensor
https://github.com/easyiot-china/libsensor https://github.com/adafruit/DHT-sensor-library https://gi ...
- HDU 6118 度度熊的交易计划 最大费用可行流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6118 题意:中文题 分析: 最小费用最大流,首先建立源点 s ,与超级汇点 t .因为生产一个商品需要 ...
- Memcached内存缓存技术
Memcached是什么,有什么作用? Memcached是一个开源的.高性能的内存缓存软件,从名称上看Mem就是内存的意思,而Cache就是缓存的意思. Memcached通过在事先规划好的内存空间 ...
- ArcGIS Server 基于Token安全验证
写在前面:只使用token并不能起到安全验证的作用,ArcGIS Server文件夹的权限是开放的,我们不需要登录Server平台即可访问服务,所以我们应该将Token验证和文件夹的安全性结合起来使用 ...
- js cookies的使用及介绍 (非常详细)
设置cookie 每个cookie都是一个名/值对,可以把下面这样一个字符串赋值给document.cookie:document.cookie="userId=828";如果要一 ...
- artdialog自定义多个按钮
在实际运用到的过程中artdialog弹出框下面的按钮不止一个 可以自己定义多个按钮 function view_show(cust_id){$.dialog({ id: 'view_c ...
- leetcode 141 142. Linked List Cycle
题目描述: 不用辅助空间判断,链表中是否有环 /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...