hdu 5228 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)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<map>
#define MOD 1000000007
using namespace std;
int a[];
int l[];//记录每个数的左边最接近得可整除的数的位置
int r[];//记录每个数的右边最接近得可整除的数的位置
int mp[];//记录之前出现过的数,判断是否是整除的数的标记数组,存的是那个数的位置
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
memset(mp,,sizeof(mp));
for(int i=;i<=n;i++)//找左边最接近的数
{
l[i]=;
for(int j=;j*j<=a[i];j++)//判断这个数是否被整除,取到根号就好
{
if(a[i]%j==)
{
if(mp[j]) l[i]=max(mp[j],l[i]);
if(mp[a[i]/j]) l[i]=max(mp[a[i]/j],l[i]);//这个是以根号为界限的右边的因子数,自己推导一下
}
}
mp[a[i]]=i;//出现过的数记录一下
}
memset(mp,,sizeof(mp));
for(int i=n;i>=;i--)找右边最接近的数
{
r[i]=n+;
for(int j=;j*j<=a[i];j++)
{
if(a[i]%j==)
{
if(mp[j]) r[i]=min(mp[j],r[i]);
if(mp[a[i]/j]) r[i]=min(mp[a[i]/j],r[i]);
}
}
mp[a[i]]=i;
}
long long sum=;
for(int i=;i<=n;i++)
{
sum+=(i-l[i])*(r[i]-i);//公式算每个数的贡献区间个数多少
}
printf("%lld\n",sum%MOD);
}
}
我个人觉得比赛的时候要有能力分清这个是否是一个求贡献的题目,下面讲下个人理解,我觉得如果一件事必须要这个成员参与
,而且有很多这类的的事,并且题目是要求每个个数之和之类的就是求贡献题
也是个人一些推断,希望对你们有用,
下面最后说一句,搞acm的小菜鸡绝不服输>_<`
hdu 5228 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多小联赛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 2167 状压dp方格取数
题意:给出一个数表,规定取出一个数后周围的八个数都不可取,求可获得的最大数字和 思路:状态压缩dp,每一行的取数方法为状态,显然,由于取数规则的限制,可取的状态并不是 1<<size_co ...
- 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 ...
随机推荐
- p1467 Runaround Numbers
直接搜就行. #include <iostream> #include <cstdio> #include <cmath> #include <algorit ...
- git 提交代码场景
1.首次提交代码到master git init git add . git commit -m '' git remote add origin +address git push -u origi ...
- python3 mail
# !usr/bin/python3# -*-coding=UTF-8-*-import smtplib # python 对SMTP的支持,smtplib这个库负责发送邮件from email.mi ...
- 笔记react router 4(五)
或许,你觉得我麻烦,明明一篇文章可以搞定的内容,非要写几篇.是不是正在吐槽我?没关系,我的目的达到了.手动傲娇( ̄∇ ̄) 然后,我们就要来聊一聊withRouter了. 我们都知道,当我在访问路由配置 ...
- java的同步实现
在java编程中,经常需要用到同步,而同步的实现使用最多的就是synchronized关键字了. synchronized关键字涉及到“锁”的概念,首先先了解一下相关锁的知识. java的内置锁:每个 ...
- 压力测试之ab命令
网站性能压力测试是服务器网站性能调优过程中必不可缺少的一环.只有让服务器处在高压情况下,才能真正体现出软件.硬件等各种设置不当所暴露出的问题. ab是apache自带的压力测试工具.ab非常实用,它不 ...
- 【LeetCode】字符串匹配
给定目标串 haystack 和模式串 needle ,返回 needle 在 haystack 中第一次出现的位置下标,若 needle 不是 haystack 的子串则返回 -1. 1. Brut ...
- Python面向对象之继承
前言: 继承是面向对象的3大特性之一,对于继承一点要注意一下4点. 一.基本查找 如果子类继承了父类,子类的实例化对象,没有的方法和属性会去父类找 class Parent(object): #父类 ...
- Tomcat修改版本号教程(CentOS)
1 到apache-tomcat安装目录下的lib子文件夹,找到catalina.jar备份该文件然后将该文件下载到本地. 2 使用winrar等工具直接打开该jar包进入到org/apache/ca ...
- 解决libvlc_media_player_stop时死锁的方法
转自:http://www.jiazi.cn/blog/?id=56 扩散该解决方法 最近需要使用VLC控件来做一个简单的流媒体播放器,在实施过程中,发现在调用libvlc_media_player_ ...