2015 Multi-University Training Contest 1记录
1001 OO’s Sequence
分析:
对于例子,能够得到,我们要求的是(1,1)(1,2)(1,3)(1,4)(1,5)(2,2)(2,3)(2,4)(2,5)(3,3)(3,4)(3,5)(4,4)(4,5)(5,5)这些范围内满足题目中所给的要求的i的个数。所以能够将两个求和符号转换为考虑原来ai序列中每个ai对于结果的贡献。
对于题目,刚好能够发现,我们仅仅须要对于每个ai求离它左右近期的因子就能够了。这样两个因子之间范围内每个i都是满足题目要求。
然后考虑求解ai因子的策略。假设对于每个ai都是每次左右分别搜索,那么一定会超时的。所以我们採取一个预处理,这里是学长教我的,方法非常巧妙。自己无法总结出来,所以还是看看代码里面怎么求的就好了。
还有。那几个10w的数组必须开在全局变量中,不然会爆栈。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int a[100000+5],r[100000+5],l[100000+5],vis[100000+5];
int main()
{
int i,j,ans,n;
while(~scanf("%d",&n))
{
if(n==0) break;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
memset(l,0,sizeof(l));
memset(vis,0,sizeof(vis));
for(i=0;i<=n;i++) r[i]=n+1;
for(i=1;i<=n;i++)
{
for(j=1;j*j<=a[i];j++)
{
if(a[i]%j!=0) continue;
if(vis[j]>l[i]&&vis[j]<i) l[i]=vis[j];
if(vis[a[i]/j]>l[i]&&vis[a[i]/j]<i) l[i]=vis[a[i]/j];
}
vis[a[i]]=i;
}
memset(vis,0,sizeof(vis));
for(i=n;i>=1;i--)
{
for(j=1;j*j<=a[i];j++)
{
if(a[i]%j!=0) continue;
if(vis[j]<r[i]&&vis[j]>i) r[i]=vis[j];
if(vis[a[i]/j]<r[i]&&vis[a[i]/j]>i) r[i]=vis[a[i]/j];
}
vis[a[i]]=i;
}
for(ans=0,i=1;i<=n;i++)
{
ans+=(r[i]-i)*(i-l[i]);
ans%=mod;
}
printf("%d\n",ans%mod);
}
return 0;
}
2015 Multi-University Training Contest 1记录的更多相关文章
- 2015 UESTC Winter Training #7【2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest】
2015 UESTC Winter Training #7 2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest 据 ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 2015 Multi-University Training Contest 8 hdu 5381 The sum of gcd
The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- 2015 Multi-University Training Contest 10(9/11)
2015 Multi-University Training Contest 10 5406 CRB and Apple 1.排序之后费用流 spfa用stack才能过 //#pragma GCC o ...
- 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】
2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...
- Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7
Root Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
随机推荐
- html中给元素添加背景图片或者gif动图
添加背景图片有四种常用的方式,分别是: repeat 完全平铺 repeat-x 横向平铺 repeat-y 纵向平铺 no-repeat 不平铺 使用示例: <!DOC ...
- Java的Math-BigInteger-Random类概述
1. Math类 Math类在java.lang包中. 常用的方法有 Math.abs(double x)返回x的绝对值. Math.max(double x,double y)返回x和y的 ...
- 山东省第六届省赛 H题:Square Number
Description In mathematics, a square number is an integer that is the square of an integer. In other ...
- python 连接ubuntu xampp mysql
>>> import MySQLdb >>> db=MySQLdb.connect(user="root",passwd="" ...
- HDU 多校1.3
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- IBM-Club IntelliJ IDEA 开发环境的安装
各位小伙伴初次使用IDE,可能还是有许多疑惑,因此这篇博客阿鲁给大家分享一下,自己平时是如何安装IntelliJ IDEA的 1.原料:安装包,直接百度搜索进入官网下载 记住是Ultimate版本呦, ...
- POJ 1722 SUBTRACT
给定一个数组a[1,2,..,n] .定义数组第i位上的减操作:把ai和ai+1换成ai - ai+1.输入一个n位数组以及目标整数t,求一个n-1次操作序列,使得最后剩下的数等于t最后输出依此操作的 ...
- [haoi2009]巧克力
鉴于河南是oi弱省,所以想来这道题也没什么人会翻出来写吧,而且这还是haoi2009的一道简单题目,所以估计也没几个人会写博客的,那么看在我这么弱的份上,我觉得是应该写一篇出来的. 这道题我是按照贪心 ...
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)(将一个数组变成严格单增数组的最少步骤)
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- [BZOJ4772]显而易见的数论(数论)
4772: 显而易见的数论 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 76 Solved: 32[Submit][Status][Discuss ...