HDU5288 OO’s Sequence
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
Sample Input
1 2 3 4 5
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define LL long long
#define MAXN 100010
using namespace std;
const LL MOD = 1e9 + ;
int a[MAXN];
LL l[MAXN], r[MAXN], pre[MAXN], last[MAXN];
int main() {
int n;
while(~scanf("%d", &n)) {
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
l[i] = , r[i] = n+;
}
memset(pre, , sizeof(pre));
memset(last, , sizeof(last)); for(int i = ; i <= n; ++i) {
for(int j = a[i]; j <= ; j += a[i]) {
//通过这个循环,如果a[i]是之前一个数的因子,一定会在后边遇到
if(pre[j] != && r[pre[j]] == n+) {
//这个数字 j (j = x * a[i])之前已经出现,且右边界是最右端
r[pre[j]] = i;
//这时更新pre[j]的右端, pre[j] 表示的是 j 最后出现的位置
}
}
pre[a[i]] = i; //当前pre[a[i]] 最后出现的位置是 i
} for(int i = n; i > ; --i) {
for(int j = a[i]; j <= ; j += a[i]) {
if(last[j] != && l[last[j]] == ) {
l[last[j]] = i;
}
}
last[a[i]] = i;
}
LL ans = ;
for(int i = ; i <= n; ++i) {
ans = (LL) (ans % MOD + (LL)(((i-l[i])*(r[i]-i)%MOD)%MOD));
ans %= MOD;
}
cout << ans << endl;
}
return ;
}
HDU5288 OO’s Sequence的更多相关文章
- hdu5288 OO’s Sequence 二分 多校联合第一场
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 解题报告 之 HDU5288 OO' s Sequence
解题报告 之 HDU5288 OO' s Sequence Description OO has got a array A of size n ,defined a function f(l,r) ...
- 2015 Multi-University Training Contest 1 - 1001 OO’s Sequence
OO’s Sequence Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Mean: 给定一个数列,让你求所有区间上满足 ...
- 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 水题
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 ...
随机推荐
- HTML5在canvas中绘制复杂形状附效果截图
HTML5在canvas中绘制复杂形状附效果截图 一.绘制复杂形状或路径 在简单的矩形不能满足需求的情况下,绘图环境提供了如下方法来绘制复杂的形状或路径. beginPath() : 开始绘制一个新路 ...
- JDI tutorial (trace example)
Components Debugger Interfaces / |--------------| / | VM | debuggee ----( |--------------| <----- ...
- nodejs开发 express路由与中间件
路由 通常HTTP URL的格式是这样的: http://host[:port][path] http表示协议. host表示主机. port为端口,可选字段,不提供时默认为80. path指定请求资 ...
- 如何修改Xampp中MySQL的root密码?
MySQL 的“root”用户默认状态是没有密码的,所以在 PHP 中您可以使用 mysql_connect("localhost","root"," ...
- CSS书写规范、命名规范、网易CSS框架NEC
网易CSS框架NEC:http://nec.netease.com/ NEC框架的CSS规范: CSS规范 - 分类方法 CSS规范 - 命名规则 CSS规范 - 代码格式 CSS规范 - 优化方案 ...
- PHP获取当前页面的URL
/** * 获取当前页面完整URL地址 * * @author 52php.cnblogs.com */ function http_get_page_url() { global $_G; if ( ...
- Gyro
Gyro 2 Plugin gyro2.jsVersion 1.19HTML5 only 本插件使用手机或平板设备上的陀螺仪和加速度传感器来控制krpano中的浏览和观看方向.Gyro2插件对比旧的陀 ...
- MySql连接数据库和操作(java)
package org.wxd.weixin.util; import java.sql.Connection;import java.sql.DriverManager;import java.sq ...
- 序列化对象为xml字符串
/// <summary> /// 序列化对象为xml字符串 /// </summary> /// <param name="obj" ...
- Unity3D LuaComponent(基于ulua)
LuaComponent可以支持配一个需要执行在这个gameObject上的lua脚本,并且每个gameObject上的lua都是一个实例 using UnityEngine; using LuaIn ...