hdu 5288 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)
1 2 3 4 5
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector> #define LL long long
#define pb push_back using namespace std; const int maxn=1e5+;
const int mod=1e9+;
const int inf=0x3f3f3f3f; int a[maxn];
int l[maxn];
int r[maxn];
vector <int> di[maxn];
vector <int> pos[maxn]; void pre_init()
{
for(int i=;i<maxn;i++){
for(int j=;j*j<=i;j++){
if(i%j==){
di[i].pb(j);
if(i/j != j)
di[i].pb(i/j);
}
}
}
} void init(int n)
{
for(int i=;i<maxn;i++){
pos[i].clear();
}
} void solve(int ); int main()
{
pre_init(); int n;
while(~scanf("%d",&n)){
init(n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
pos[a[i]].pb(i);
}
solve(n);
}
return ;
} void solve(int n)
{
for(int i=;i<=n;i++){
l[i]=,r[i]=n;
} for(int i=;i<=n;i++){
for(int j=;j<di[a[i]].size();j++){
int k=di[a[i]][j]; int left=,right=pos[k].size()-; if(right<left)
continue; if(pos[k][left]<i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]>=i)
right=mid;
else
left=mid;
}
if(pos[k][right]<i)
l[i]=max(l[i],pos[k][right]+);
else
l[i]=max(l[i],pos[k][left]+);
} left=,right=pos[k].size()-;
if(pos[k][right]>i){
while(right-left>){
int mid=(left+right)>>;
if(pos[k][mid]<=i)
left=mid;
else
right=mid;
}
if(pos[k][left]>i)
r[i]=min(r[i],pos[k][left]-);
else
r[i]=min(r[i],pos[k][right]-);
} }
} /*
for(int i=1;i<=n;i++)
printf("%d %d\n",l[i],r[i]);
*/ LL ret=;
for(int i=;i<=n;i++){
ret+=(i-l[i]+)*(r[i]-i+)%mod;
ret=(ret+mod)%mod;
} printf("%I64d\n",ret);
return ;
}
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 (技巧)
题目链接: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——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 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多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 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
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- HDU 1024 Max Sum Plus Plus --- dp+滚动数组
HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...
- android图像处理系列之三--图片色调饱和度、色相、亮度处理
原图: 处理后: 下面贴代码: 一.图片处理层: package com.jacp.tone.view; import java.util.ArrayList; import android.cont ...
- Bitmap 之 getPixels() 的 stride
学习Graphics中遇到位图(Bitmap)中getPixels()方法,对该方法的用法大体理解,但对其中的stride参数却不明白具体的用法以及用意,现记述过程如下: getPixels()方法的 ...
- _appstart.cshtml,_pagestart.cshtml,_viewstart.cshtml
ASP.NET MVC3 系列教程 – Web Pages 1.0 I:Web Pages 1.0中以"_"开头的特别文件(文件命名时不区分大小写) "_appstart ...
- Android Camera 相机程序编写
Android Camera 相机程序编写 要自己写一个相机应用直接使用相机硬件,首先应用需要一个权限设置,在AndroidManifest.xml中加上使用设备相机的权限: <uses-per ...
- java编辑器eclipse如何更改jdk版本
第一步:右键点击项目选择properties 第二步:选择Java Build Path 第三步:选择libraries 第四步:选中当前jre再点击右侧Edit 第五步: ...
- DataList与Repeater嵌套绑定
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...
- openstack命令行
openstack的每一个子项目(project)都有自己对应的命令行API,所有的这些API都是基于RESTful的,python代码实现的API.也就是说,这些API都是基于HTTP实现的,所以A ...
- svn钩子(hooks)
首先你需要搭建出自己的svn环境出来,并能成功导入导出,并且了解svn,这是看这篇文章的前提.... 出于公司开发部需要svn同步更新服务器代码,需要用到svn钩子(hooks)技术,以前从来没听过, ...
- LinearLayout和RelativeLayout 区别
LinearLayout和RelativeLayout转自:http://blog.csdn.net/w176236767/article/details/6605848共有属性:java代码中通过b ...