HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=5288
题面:
OO’s Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 985 Accepted Submission(s): 375
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)
5
1 2 3 4 5
23
解题:
仅仅想到从左到右去找近期的不合法点。没想到从右往左找,那么答案就出来了。事实上数据范围那么小,就已经是一种暗示了。能够用数组记录下其最后出现的位置。注意扫的操作,要和记录同一时候进行。注意小心处理1的情况就好。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#define mod 1000000007
#define maxn 100010
#define LL long long
using namespace std;
int t,le[100010],ri[100010],store[100010],pre[100010],tmp,root;
LL ans;
int main()
{
while(~scanf("%d",&t))
{
ans=0;
for(int i=1;i<=t;i++)
scanf("%d",&store[i]);
for(int i=1;i<=t;i++)
pre[i]=0;
for(int i=1;i<=t;i++)
{
tmp=1;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=max(tmp,pre[j]+1);
tmp=max(tmp,pre[store[i]/j]+1);
}
}
le[i]=tmp;
pre[store[i]]=i;
}
for(int i=1;i<=t;i++)
pre[i]=t+1;
for(int i=t;i>=1;i--)
{
tmp=t;
root=sqrt((double)store[i]);
for(int j=1;j<=root;j++)
{
if(store[i]%j==0)
{
tmp=min(pre[j]-1,tmp);
tmp=min(tmp,pre[store[i]/j]-1);
}
}
ri[i]=tmp;
pre[store[i]]=i;
}
/*for(int i=1;i<=t;i++)
cout<<i<<" "<<le[i]<<" "<<ri[i]<<endl;*/
for(int i=1;i<=t;i++)
{
ans=(ans+1LL*(i-le[i]+1)*(ri[i]-i+1))%mod;
}
printf("%lld\n",ans);
}
return 0;
}
HDU 5288 OO‘s sequence (技巧)的更多相关文章
- 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 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 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多小联赛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)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- C#多线程和线程同步总结
Thread 没有参数的线程启动 Thread newThread = new Thread(new ThreadStart(DoWork)); newThread.Start(); 有参数的线程启动 ...
- app.config 配置多项 配置集合 自定义配置(4) 自动增加配置项到配置文件的两种方法
一,按照xml文件处理: 配置文件如下图(最后的图片). 自动写入configSections和configSections的实例 1.自动写入configSections Configuration ...
- this和static关键字
this和static关键字 一.关键字this this表示对象自身的引用 this的作用 1.用来区别当前类对象的成员与参数成员 2.用来调用其它构造方法 构造方法: 1.每个类默认情况都有一个默 ...
- 网页如何展示PPT文档
最近再做一个新项目,其中有一个难点,就是如何在网页上展示PPT,我网上找到了几种方法,但是真正符合我目前这个项目的就只有这一种方法了, 使用PowerPoint to Flash将ppt文 ...
- 在动态链接库dll中弹出对话框
在动态链接库dll中弹出对话框步骤: 1.添加Dialog资源,然后在资源视图的对话框界面右击添加类,输入类名MyDlg,使得其继承与CDialogEx.(继承CDialog应该也可以)2.在新生成的 ...
- F - Capture
F - Capture 题链 题意 给你两种颜色的物品,有n组,每组有第一种颜色有w个,第二种为d个,每组必须选一种,求最后第一种颜色占的比值不低于K的最少需要选第一种的组数. 思路 首先没组都选第一 ...
- C语言之赋值
#include<stdio.h>/*void change(int m,int n){ int t; t=m; m=n; n=t;}*/int main(){//交换两杯水,需要一个空杯 ...
- 快速搭建一个本地的FTP服务器
快速搭建一个本地的FTP服务器 如果需要开发FTP文件上传下载功能,那么需要在本机上搭建一个本地FTP服务器,方便调试. 第一步:配置IIS Web服务器 1.1 控制面板中找到"程序& ...
- 一步步搭建Retrofit+RxJava+MVP网络请求框架(一)
首先,展示一下封装好之后的项目的层级结构. 1.先创建一个RetrofitApiService.java package com.xdw.retrofitrxmvpdemo.http; import ...
- 51Nod--1006 lcs
1006 最长公共子序列Lcs 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). ...