/*
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. 高性能页面加载技术(流水线加载)BigPipe的C#简单实现(附源码)

    一,BigPipe简介 BigPipe是一个重新设计的基础动态网页服务体系.大体思路是,分解网页成叫做Pagelets的小块,然后通过Web服务器和浏览器建立管道并管理他们在不同阶段的运行.这是类似于 ...

  2. bzoj 2002: [Hnoi2010]Bounce 弹飞绵羊 動態樹

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 4055  Solved: 2172[Submi ...

  3. BZOJ 2242 计算器

    Description 你被要求设计一个计算器完成以下三项任务: \(1.\)给定\(y,z,p\),计算\(y^{z}\;mod\;P\)的值: \(2.\)给定\(y,z,p\),计算满足\(xy ...

  4. 跨终端Web之Hybrid App

    Native App(以下简称Native)和Mobile Web(以下简称Web)二者混合开发的产物被称为Hybrid App(以下简称Hybrid).Hybrid并不是什么新概念,最早可以追溯到S ...

  5. rm加转义很危险

    rm -r 想转义一个空格字符,转得不对 -r, -R, --recursive 递归删除目录及其内容 连续rm了n个不想rm的文件夹.%>_<% 想起来以前有人也因为rm的失误把整个wo ...

  6. Connect them

    zoj3204: 最小生成树,要求最小字典序的解. 用kruscal算法,先排序,输出的时候也要排序. /* zoj3204 解题思路: 赤裸裸的最小生成树.只是要求输出字典序最小的连接方案. 所以在 ...

  7. 【UVA1371】Period (二分+DP)

    题意: 给出两个字符串A,B将B分解成若干个子字符串,然后每个子字符串都要经过编辑变成字符串A,所有子串中编辑最多的次数即为当前状态下的最大编辑次数,要求求最小的最大编辑次数. 编辑操作包括修改.删除 ...

  8. 计算字符串的最长回文子串 :Manacher算法介绍

    转自: http://www.open-open.com/lib/view/open1419150233417.html Manacher算法 在介绍算法之前,首先介绍一下什么是回文串,所谓回文串,简 ...

  9. PHP+MYSQL实现输出打印数据库表结构和输出表内容

    效果图1 <form id="form1" name="form1" action="2.php" method="get& ...

  10. Node.js权威指南 (1) - Node.js介绍

    1.1 Node.js概述 / 2 1.1.1 使用Node.js能够解决什么问题 / 2 1.1.2 实现高性能服务器 / 2 1.1.3 非阻塞型I/O及事件环机制 / 2 1.1.4 Node. ...