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 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 a i mod a j=0,now OO want to know
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 a i(0 < a i <= 10000)
Output
For each tests: ouput a line contain a number ans.
Sample Input
5
1 2 3 4 5
Sample Output
23
这题的题意是后来看了题解才懂的,意思是给定一个序列,对于每一个数,包括这个数的区间里的其他的数都不是这个数的因数,求对于每一个数的区间的个数的总和。
也就是说对于任何一个数,往左找到第一个它的因数的位置记作l,往右找到它的第一个因数的位置记作r,那么这个数对应的区间的个数是(i-l)*(r-i),然后对所有的数求一个和就可以了。
因为这里数的范围只有1e4,所以一开始预处理1e4以内的数的因数存在vector[N]里。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll; const int maxn = 1e5+;
const int N = 1e4+;
const int mol = 1e9+;
int arr[maxn],l[maxn],r[maxn],vis[N];
vector <int> vi[N]; int main()
{
for(int i=;i<N;i++)
for(int j=;j<=sqrt(i);j++)
if(i%j == )
{
vi[i].push_back(j);
if(j*j != i) vi[i].push_back(i/j);
}
int n;
while(~scanf("%d",&n))
{
memset(l,,sizeof(l));
memset(r,,sizeof(r));
memset(vis,,sizeof(vis));
ll ans = ;
for(int i=;i<=n;i++)
scanf("%d",&arr[i]);
for(int i=;i<=n;i++)
{
int tp = ;
for(int j=;j<vi[arr[i]].size();j++)
tp = max(tp,vis[vi[arr[i]][j]]);
l[i] = tp;
vis[arr[i]] = i;
}
for(int i=;i<N;i++) vis[i] = n+;
for(int i=n;i>;i--)
{
int tp = n+;
for(int j=;j<vi[arr[i]].size();j++)
tp = min(tp,vis[vi[arr[i]][j]]);
r[i] = tp;
vis[arr[i]] = i;
}
for(int i=;i<=n;i++)
ans = (ans + 1LL*(i-l[i])*(r[i]-i) % mol) % mol;
printf("%lld\n",ans);
}
}
HDU 5288 OO’s Sequence [数学]的更多相关文章
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- 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(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(计数)
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)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- 流量监控---iftop
一.iftop是什么? iftop是类似于top的实时流量监控工具. 官方网站:http://www.ex-parrot.com/~pdw/iftop/ 二.iftop有什么用? iftop可以用来监 ...
- Mybatis批量插入的代码实现
简单的学习总结一下,希望能帮到需要的同学! 1.mapper.xml文件sql语句如下: <insert id="insertBatch" parameterType=&qu ...
- gradle springboot打包时忽略某个配置文件
jar { exclude "**/bootstrap.properties" }
- Tab切换效果(修改)
前几天我写了这个切换效果,但是是只传一个值的函数,经过各位大牛的指点发现还是有些问题的,于是经过我不懈的努力,完善了代码: 传递多个参数替代函数里面包含事件这个问题: html代码: <div ...
- SCOI2003 严格N元树
SCOI2003 严格N元树 Description 如果一棵树的所有非叶节点都恰好有n个儿子,那么我们称它为严格n元树.如果该树中最底层的节点深度为d (根的深度为0),那么我们称它为一棵深度为d的 ...
- Linux学习一:图解CentOS 6.5安装步骤
1 进入安装界面 2 选择语言 3 选择键盘 4 选择存储类型 5 是否格式化硬盘 6 设置主机名 7 配置网卡 (1)选择网卡并编辑 (2)配置IPv4 (3)查看虚拟网络编辑器 NAT设置 DHC ...
- android onConfigurationChanged的那点事
Android学习笔记——关于onConfigurationChanged 从事Android开发,免不了会在应用里嵌入一些广告SDK,在嵌入了众多SDK后,发现几乎每个要求在AndroidMan ...
- python 中的一些小命令
- HDU 1575 EASY
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- linux c获取mac
#include <stdio.h> #include <string.h> #include <net/if.h> #include <sys/ioctl. ...