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/ ...
随机推荐
- The Lost Art of C Structure Packing
对齐要求 首先需要了解的是,对于现代处理器,C编译器在内存中放置基本C数据类型的方式受到约束,以令内存的访问速度更快. 在x86或ARM处理器中,基本C数据类型通常并不存储于内存中的随机字节地址.实际 ...
- php生成的中文文件名会变成乱码,应该这样解决
现在php有很多类库,会生成文件,比如生成zip文件,生成二维码等等.这些类库用起来很爽,但是一旦生成带有中文的文件名,极有可能出现乱码. 问题:生成的中文文件名会变成乱码 解决:使用函数:iconv ...
- 【HDOJ】2589 正方形划分
暴力DFS /* 2589 */ #include <cstdio> #include <cstring> #include <cstdlib> #define M ...
- 连接MySQL数据库得到错误“Unable to find the requested .Net Framework Data Provider”
Registering DbProviderFactories Each .NET Framework data provider that supports a factory-based cl ...
- VM Depot 镜像新增系列II – 学习管理系统,内容管理系统以及平台管理工具
发布于 2014-06-23 作者 刘 天栋 继上周企业管理软件和电子商务镜像的加盟之后,我们看到又有一批内容管理解决方案(CMS),学习管理解决方案(LMS)以及平台管理工具 (如 Open ...
- Delphi 编写的Web Service
一编写服务程序 第一步:File----->New----->Other------>WebServices----->Soap Server Application选择I ...
- LoadRunner监控Windows和Linux常见问题
LoadRunner 加载监听服务器的步骤如下: 1.在 LoadRunner Controller 下,将工作面板切换到 Run状态,Available Graphs 栏 ,System Resou ...
- MyEclipse中web服务器的三种配置方式
初学Javaweb开发的人们都会遇到一个问题,就是服务器环境的搭建配置问题.下面介绍三种服务器的搭建方式. 直接修改server.xml文件 当你写了一个web应用程序(jsp/servlet),想通 ...
- Android学习笔记(一)Android应用程序的组成部分
Android应用程序由松散耦合的组件组成,并使用应用程序Manifest绑定到一起:应用程序Manifest描述了每一组件和它们之间的交互方式,还用于指定应用程序元数据.其硬件和平台要求.外部库以及 ...
- 适配器模式 java
结构模式:将类和对象结合在一起构成更大的结构,就像是搭积木. 1.适配器模式 源接口---适配器--目标接口 2.使用场景: 现在你有一个很古老的类,里面的一些方法很有用,你如何使用这些方法? 当然你 ...