HDU 5288 OO’s Sequence
来源:互联网 发布:淘宝装修模板 编辑:程序博客网 时间:2024/05/16 01:49
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+3;const int N = 1e4+3;const int mol = 1e9+7;int arr[maxn],l[maxn],r[maxn],vis[N];vector <int> vi[N];int main(){ for(int i=1;i<N;i++) for(int j=1;j<=sqrt(i);j++) if(i%j == 0) { vi[i].push_back(j); if(j*j != i) vi[i].push_back(i/j); } int n; while(~scanf("%d",&n)) { memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); memset(vis,0,sizeof(vis)); ll ans = 0; for(int i=1;i<=n;i++) scanf("%d",&arr[i]); for(int i=1;i<=n;i++) { int tp = 0; for(int j=0;j<vi[arr[i]].size();j++) tp = max(tp,vis[vi[arr[i]][j]]); l[i] = tp; vis[arr[i]] = i; } for(int i=0;i<N;i++) vis[i] = n+1; for(int i=n;i>0;i--) { int tp = n+1; for(int j=0;j<vi[arr[i]].size();j++) tp = min(tp,vis[vi[arr[i]][j]]); r[i] = tp; vis[arr[i]] = i; } for(int i=1;i<=n;i++) ans = (ans + 1LL*(i-l[i])*(r[i]-i) % mol) % mol; printf("%lld\n",ans); }}
阅读全文
0 0
- hdu 5288OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- HDU 5288 OO’s Sequence
- 【瞎搞】HDU 5288 OO’s Sequence
- HDU 5288 OO’s Sequence 区间个数
- [思路题] hdu 5288 OO’s Sequence
- hdu 5288 OO’s Sequence 分解因子
- HDU 5288 OO’s Sequence (二分查找)
- コンピュターグラフィックス COMPUTER GRAPHICS[FOR CG ENGINEERS]-Chapter7-0708
- 如何理解v-model的实质为语法糖
- Android 使用Glide实现圆形和圆角图片
- 七月算法深度学习 第三期 学习笔记-第二节 DNN与混合网络
- 日常小记整理2
- HDU 5288 OO’s Sequence
- 有关子矩阵最大累加和的总结
- MySql黑丝带
- 数据分析(入门篇)-第二章-玩转数据分析-Part6(Excel数据分析工具库-回归分析)
- xamarin android自定义spinner
- JavaWeb三大技术之Listener
- 有关完全二叉树求节点数和前缀树求字符串是否重复的两道算法题
- 子集生成算法
- JRE的安装及环境变量配置