思维题 HDOJ 5288 OO’s Sequence
/*
定义两个数组,l[i]和r[i]表示第i个数左侧右侧接近它且值是a[i]因子的位置,
第i个数被选择后贡献的值是(r[i]-i)*(i-l[i]),每个数都枚举它的因子,更新l[i], r[i],复杂度O(n*sqrt(a[i]))
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN];
int l[MAXN], r[MAXN];
int pos[]; int main(void) { //HDOJ 5288 OO’s Sequence
//freopen ("1001.in", "r", stdin);
int n;
while (scanf ("%d", &n) == ) {
for (int i=; i<=n; ++i) {
scanf ("%d", &a[i]);
} int ans = ;
memset (pos, , sizeof (pos));
memset (l, , sizeof (l));
for (int i=; i<=n; ++i) {
for (int j=; j<=sqrt (a[i]); ++j) {
if (a[i] % j == ) {
if (pos[j] > l[i]) l[i] = pos[j];
if (pos[a[i]/j] > l[i]) l[i] = pos[a[i]/j];
}
}
pos[a[i]] = i;
}
for (int i=; i<=; ++i) pos[i] = n + ;
for (int i=; i<=n; ++i) r[i] = n + ;
for (int i=n; i>=; --i) {
for (int j=; j<=sqrt (a[i]); ++j) {
if (a[i] % j == ) {
if (pos[j] < r[i]) r[i] = pos[j];
if (pos[a[i]/j] < r[i]) r[i] = pos[a[i]/j];
}
}
pos[a[i]] = i;
}
for (int i=; i<=n; ++i) {
ans = (ans + (r[i] - i) * (i - l[i]) % MOD) % MOD;
}
printf ("%d\n", ans);
} return ;
}
思维题 HDOJ 5288 OO’s Sequence的更多相关文章
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdoj 5288 OO’s Sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 //*************头文件区************* #include<ios ...
- 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 [数学]
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 题目连接: 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 ...
- 【HDOJ】5288 OO’s Sequence
二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...
随机推荐
- [K/3Cloud] 关于单据转换的问题
1. 单据转换,是否支持重复下推,支持新增下推和更新下推? 答:支持重复下推,是否允许下推受以下因素: 1).源分录是否是有效状态(源单单头状态会自动影响分录,下同),例如已审核.未关闭.未作废: 2 ...
- [TJOI2010]中位数
题目描述 给定一个由N个元素组成的整数序列,现在有两种操作: 1 add a 在该序列的最后添加一个整数a,组成长度为N + 1的整数序列 2 mid 输出当前序列的中位数 中位数是指将一个序列按照从 ...
- [bzoj2506]calc_分块处理
calc bzoj-2506 题目大意:给一个长度为n的非负整数序列A1,A2,…,An.现有m个询问,每次询问给出l,r,p,k,问满足l<=i<=r且Ai mod p = k的值i的个 ...
- codevs——1385 挤牛奶
1385 挤牛奶 USACO 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 查看运行结果 题目描述 Description 三个农民每天清 ...
- JSON与对象之间的转换
import com.alibaba.fastjson.JSON;import com.fasterxml.jackson.databind.ObjectMapper;import com.faste ...
- Ubuntu 16.04 GNOME下解决Sublime Text3中文输入(ibus)(转)
解决方法: 1.进入Sublime Text3插件管理文件夹 cd ~/.config/sublime-text-3/Packages 2.获取InputHelper插件 git clone http ...
- X-pack-6.2.4破解
1.前言: X-pack是elasticsearch的一个扩展包,将安全,警告,监视,图形和报告功能捆绑在一个易于安装的软件包中,虽然x-pack被设计为一个无缝的工作,但是你可以轻松的启用或者关闭一 ...
- [TypeScript] Use TypeScript’s never Type for Exhaustiveness Checking
TypeScript 2.0 introduced a new primitive type called never, the type of values that never occur. It ...
- C#.NET如何判断是否有缺少的using
调试的时候会报错,红色的波浪线表示出错的位置,右击即可找到对应的using
- 开源 免费 java CMS - FreeCMS2.1 会员3.9我的收藏
项目地址:http://www.freeteam.cn/ 我的收藏 从左側管理菜单点击我的收藏进入.在这里能够查看当前登录会员的全部收藏记录. 查看收藏 点击标题能够查看收藏内容. 删除收藏 选择收藏 ...