hdu 3450 Counting Sequences
/*
n*n暴力 这个很好想
*/
#include<cstdio>
#define maxn 100010
#define mod 9901
using namespace std;
int n,k,a[maxn],f[maxn],ans;
int Abs(int a){
return a<?-a:a;
}
int max(int a,int b){
return a<b?b:a;
}
int main()
{
freopen("cin.txt","r",stdin);
freopen("right.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(Abs(a[i]-a[j])>k)continue;
f[i]=(f[i]+f[j]+)%mod;
}
ans=(ans+f[i])%mod;
}
printf("%d\n",ans);
return ;
}
/*
搞个数据结构来优化
开始想错了题意 就写了线段树+离散化
后来反应过来了..树状数组就行QAQ
开始写wa了 改着改着就搞出了两个线段树
这就跑的有点慢了 但A点没问题
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
#define mod 9901
#define lc k*2
#define rc k*2+1
#define mid (l+r)/2
using namespace std;
int n,m,d,a[maxn],c[maxn];
int sum[maxn*],tot[maxn*];
int init(){
int x=,f=;char s=getchar();
while(s<''||s>''){if(s=='-')f=-;s=getchar();}
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x*f;
}
void Change(int k,int l,int r,int x,int y){
if(l==x&&r==x){
sum[k]=(sum[k]+y)%mod;return;
}
if(x<=mid)Change(lc,l,mid,x,y);
else Change(rc,mid+,r,x,y);
sum[k]=(sum[lc]+sum[rc])%mod;
}
int Query(int k,int l,int r,int x,int y){
if(x<=l&&y>=r){
return sum[k];
}
int ret=;
if(x<=mid)ret=(ret+Query(lc,l,mid,x,y))%mod;
if(y>mid)ret=(ret+Query(rc,mid+,r,x,y))%mod;
return ret;
}void change(int k,int l,int r,int x,int y){
if(l==x&&r==x){
tot[k]=(tot[k]+y)%mod;return;
}
if(x<=mid)change(lc,l,mid,x,y);
else change(rc,mid+,r,x,y);
tot[k]=(tot[lc]+tot[rc])%mod;
}
int query(int k,int l,int r,int x,int y){
if(x<=l&&y>=r){
return tot[k];
}
int ret=;
if(x<=mid)ret=(ret+query(lc,l,mid,x,y))%mod;
if(y>mid)ret=(ret+query(rc,mid+,r,x,y))%mod;
return ret;
}
int main()
{
while(~scanf("%d%d",&n,&d)){
memset(tot,,sizeof(tot));
memset(sum,,sizeof(sum));
m=;
for(int i=;i<=n;i++){
a[i]=init();c[i]=a[i];
}
sort(c+,c++n);
m=unique(c+,c++n)-c-;
int L,R,M,S,s;
for(int i=;i<=n;i++){
L=lower_bound(c+,c++m,a[i]-d)-c;
R=upper_bound(c+,c++m,a[i]+d)-c-;
M=lower_bound(c+,c++m,a[i])-c;
S=Query(,,m,L,R);
s=query(,,m,L,R);
Change(,,m,M,S+s);
change(,,m,M,);
}
printf("%d\n",sum[]);
}
return ;
}
hdu 3450 Counting Sequences的更多相关文章
- HDU 3450 Counting Sequences(线段树)
Counting Sequences Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Other ...
- hdu 5862 Counting Intersections
传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)
传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 5862 Counting Intersections (树状数组)
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 5862 Counting Intersections 扫描线+树状数组
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/ ...
随机推荐
- 如何分析matlab程序的主要效率问题
利用profile on 在需要分析效率的程序段前后加入 profile on profile off 然后,在common line中输入profile viewer即可观察到这段程序的效率
- Chrome控制台
先的简单介绍一下chrome的控制台,打开chrome浏览器,按f12就可以轻松的打开控制台 大家可以看到控制台里面有一首诗还有其它信息,如果想清空控制台,可以点击左上角那个来清空,当然也可以通过在控 ...
- 【HDU3081】Marriage Match II (二分+最大流)
Description Presumably, you all have known the question of stable marriage match. A girl will choose ...
- php调用linux命令
php有以下接口可提供执行外部函数: system() exec() popen() 但要使用上面几个函数,首先,要配置php.ini配置文件.修改配置文件如下: safe_mode = off; 改 ...
- java中如何实现全局变量
有时一个项目中会多处涉及到路径,当你把这个项目移植到别的电脑上时就要一一修改这些路径,过程十分繁琐,所以一个全局变量在这时是必不可少的. 遗憾的是java等oo语言并没有全局变量,这怎么办呢?下面介绍 ...
- 多台Mac电脑使用一个apple开发者账号
直接从已安装好的机器上导出私有密钥的,具体方法如下: Xcode的organizer的IPHONE DEVELOPMENT --->Developer Profile里自带的Export和Imp ...
- leetcode 栈 括号匹配
https://oj.leetcode.com/problems/valid-parentheses/ 遇到左括号入栈,遇到右括号出栈找匹配,为空或不匹配为空, public class Soluti ...
- UVa 10294 Arif in Dhaka (First Love Part 2)(置换)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...
- Distinct Substrings - spoj 694(不重复子串个数)
题目大意:RT 分析:练手题目....后缀数组确实很强大.....多理解height数组, 切勿使用模版,后缀数组本身就有很多细节,多犯错更有利理解这个算法. 代码如下: ========== ...
- 【设计模式 - 14】之命令模式(Command)
1 模式简介 命令模式的定义: 命令模式将命令封装成对象,从而使调用一个命令变为调用一个对象的指定方法. 命令模式的优点: 1) 降低了系统耦合度: 2) 新的命 ...