HDU 5288 OO’s Sequence
题意: 给你一个序列, 有一个函数 F(L,R) 其中 ai 均不能 被 aL … aR整除的 函数值是这个ai个数
思路 : 反过来求 满足这样的条件的 ai 的区间,然后求和
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int maxn = 100002;
const LL MOD = 1e9 + 7;
vector<int> Cnt[10005];
int Left[maxn], Right[maxn];
int Num[maxn],Vis[maxn];
int Scan()
{
int res = 0, ch, flag = 0; if((ch = getchar()) == '-') //判断正负
flag = 1; else if(ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while((ch = getchar()) >= '0' && ch <= '9' )
res = res * 10 + ch - '0'; return flag ? -res : res;
}
void Init() {
for(int i = 1; i <= 10005; ++i)
{
for(int j = 1; j <= i; ++j)
if(i % j == 0) Cnt[i].push_back(j);
}
}
int main() {
int n;
Init();
while(scanf("%d",&n) != EOF) {
for(int i = 0; i < n; ++i) Num[i] = Scan();
memset(Left,-1,sizeof(Left));
memset(Right,-1,sizeof(Right));
memset(Vis,-1,sizeof(Vis));
//GET LEFT
for(int i = 0; i < n; ++i) {
for(int j = 0; j < Cnt[Num[i]].size(); ++j) {
int tmp = Cnt[Num[i]][j];
if(Vis[tmp] != -1 && Num[i] % tmp == 0) {
if(Left[i] == -1) Left[i] = Vis[tmp] + 1;
else Left[i] = max(Left[i],Vis[tmp]+1);
}
}
Vis[Num[i]] = i;
}
//GET RIGHT
memset(Vis,-1,sizeof(Vis));
for(int i = n-1; i >= 0; --i) {
for(int j = 0; j < Cnt[Num[i]].size(); ++j) {
int tmp = Cnt[Num[i]][j];
if(Vis[tmp] != -1 && Num[i] % tmp == 0) {
if(Right[i] == -1) Right[i] = Vis[tmp] - 1;
else Right[i] = min(Right[i],Vis[tmp]-1);
}
}
Vis[Num[i]] = i;
}
for(int i = 0; i < n; ++i) {
if(Left[i] == -1) Left[i] = 0;
if(Right[i] == -1) Right[i] = n-1;
}
LL ans = 0;
for(LL i = 0; i < n; ++i) {
LL L = i - Left[i] + 1;
LL R = Right[i] - i + 1;
ans = (ans + L * R) % MOD;
}
printf("%I64d\n",ans);
}
}
HDU 5288 OO’s Sequence的更多相关文章
- HDU 5288 OO's sequence (2015多校第一场 二分查找)
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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 (技巧)
题目链接: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(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——————【技巧题】
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 枚举+二分
Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...
随机推荐
- 百度地图手机端单触点单击和长按事件,解决部分手机(小米手机)地图单击事件失效,多触点、拖动依然触发长按的bug
/** * Author 岳晓 * * 对百度地图的事件扩展,目前扩展了fastclick和longclick, * 解决某些设备click不执行的问题 * 解决长按事件在拖动.多触点依然执行的bug ...
- javascript面向对象精要第三章对象整理精要
什么是对象的数据属性?什么是对象的访问器属性?[put]方法是默认创建数据属性的,访 问器属性不包含值而是定义了一个单属性被读取时调用的函数(getter)和当一个属性被写入时 调用的函数(sette ...
- 外显子分析弹错解决方案:Invalid command line: Cannot process the provided BAM/CRAM file(s) because they were not indexed.
出现这种问题说明bam/cram文件没有进行index. Samtool能解决这个问题,以bam文件为例,输入以下命令行即可解决问题: /path/to/your/samtools index fil ...
- (Arrays.sort() 或 map) Ignatius and the Princess IV hdu1029
Ignatius and the Princess IV 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 借鉴链接:https://blog.csd ...
- call_user_func 和 call_user_func_array用法
说明 call_user_func 和 call_user_func_array 相同:都可以调用函数和类内部的函数,不同:不同的是传递的参数不同,前者是一个参数一个参数传递, 后者是传递array参 ...
- GO语言的进阶之路-goroutine(并发)
GO语言的进阶之路-goroutine(并发) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 有人把Go比作21世纪的C 语言,第一是因为 Go语言设计简单,第二,21世纪最重要的 ...
- Hadoop记录-hadoop介绍
1.hadoop是什么? Hadoop 是Apache基金会下一个开源的大数据分布式计算平台,它以分布式文件系统HDFS和MapReduce算法为核心,为用户提供了系统底层细节透明的分布式基础架构. ...
- vue自学入门-3(vue第一个例子)
1.安装后打开8080端口,http://localhost:8080/#/ 2.进入项目目录 2.默认路由 3.修改文件index.js 将Import HelloWorld一句修改为 import ...
- new和delete
和 sizeof 类似,sizeof不是函数,它是一个操作符,它在编译期就完成了计算,在函数运行期间它已经是一个常数值了. int a; sizeof(int) = 4; sizeof(a) = 4; ...
- VS中空项目、win32项目、控制台程序的区别(转)
空项目,大多数想单纯创建c++工程的新同学,打开vs后很可能不知道选择创建什么工程,这时候请相信我,空项目是你最好的选择.因为空工程不包含任何的源代码文件,接下来你只需要在相应的源代码文件夹和头文件文 ...