/*
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的更多相关文章

  1. HDU 3450 Counting Sequences(线段树)

    Counting Sequences Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Other ...

  2. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

  3. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  4. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  5. Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)

    传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...

  6. HDU 1264 Counting Squares(线段树求面积的并)

    Counting Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

  8. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. HDU 5862 Counting Intersections 扫描线+树状数组

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/ ...

随机推荐

  1. python使用__future__

    Python的新版本会引入新的功能,但是,实际上这些功能在上一个老版本中就已经存在了.要“试用”某一新的特性,就可以通过导入__future__模块的某些功能来实现. 例如,Python 2.7的整数 ...

  2. [BZOJ 3564] [SHOI2014] 信号增幅仪 【最小圆覆盖】

    题目链接:BZOJ - 3564 题目分析 求最小椭圆覆盖,题目给定了椭圆的长轴与 x 轴正方向的夹角,给定了椭圆长轴与短轴的比值. 那么先将所有点旋转一个角度,使椭圆长轴与 x 轴平行,再将所有点的 ...

  3. SAP Crystal Dashboard Design 2011 win7 x64 安装

    suggest: unZip the setup package to C:\dashboard\  (make sure that the path cannot contain non-unico ...

  4. uva 1203 - Argus

    简单的优先队列的应用: 代码: #include<queue> #include<cstdio> using namespace std; struct node { int ...

  5. 浅谈C# .Net技术面试 , 正在找工作的人一定要看看

    1.引子 最近一直在负责.net(B/S方向)技术面试相关的工作,前前后后面试了不少人,但是通过率较低,大概只有20%左右:有颇多感慨. 最近也一直比较困惑,原因究竟是什么? 是我们要求太高,应聘者本 ...

  6. 用 Webgoat 撬动地球,看安全测试的引路石!

    测试工程师是很多人迈进软件行业的起点.从负责很小的局部到把握整个产品的质量,每个人花费的时间长短不一--从功能到性能.可用性到容错性.从兼容性到扩展性.稳定性到健壮性--方方面面逐渐做广做深. 不过, ...

  7. win7电脑自动关机怎么设置

    WIN7系统自带了关机工具的,下面是步骤 1.“开始”-右键点击“计算机”选择“管理”,在左侧界面中选择“任务计划程序”. 2.在右侧界面中选择“创建基本任务”(向导式创建任务,推荐新手使用)或者“创 ...

  8. 使用m2eclipse搭建Web项目

    这篇文章已经指导好了:http://www.cnblogs.com/quanyongan/archive/2013/04/21/3033838.html

  9. 【CF】220B Little Elephant and Array

    区间动态统计的好题. /* */ #include <iostream> #include <string> #include <map> #include < ...

  10. java学习面向对象之多态

    如何理解多态,让我们举个例子来描述一下,因为单纯的说多态大家可能不理解: abstract class Animal { ; abstract void eat(); public void run( ...