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/ ...
随机推荐
- 从零开始学习MySQL2---MySQL的安装与配置(只有Windows)
因为我电脑只装了Windows系统,故而,只整理了在Windows系统下的安装方式 截图比较麻烦,故而多引用百度经验. Windows平台下安装与配置MySQL 5.6 下载,网址:http://de ...
- linux socket使用经验总结
1. scoket函数中PF_INET AF_INET区别 在UNIX系列中,PF_INET表示poxis, BSD系列用AF_INET 2. in_addr_t inet_addr(const ...
- 使用Python实现Hadoop MapReduce程序
转自:使用Python实现Hadoop MapReduce程序 英文原文:Writing an Hadoop MapReduce Program in Python 根据上面两篇文章,下面是我在自己的 ...
- .rdp 文件参数详解
Overview of .rdp file settings Setting Type Default value Description and possible values Settable f ...
- 《More Effective C++》 条款5 谨慎定义类型转换函数
---恢复内容开始--- C++编译器能够在两种数据类型之间进行隐式转换(implicit conversions),它继承了C语言的转换方法,例如允许把char隐式转换为int和从short隐式转换 ...
- oracle 安装, oem 不能正常使用,em安装失败、找不到dbconsole服务
OracleDBControl启动失败Unable to determine local host from URL REPOSITORY_URL=http://your-url.co 通过emca创 ...
- Android 中的MVC与数据流动
今天看了一个Android的Training生命周期转换的例子,顿觉得他的设计非常巧妙,我的分析如下: 1.在com.example.android.lifecycle包中有: 3个正常的全屏acti ...
- PHP SSL Module "subjectAltNames"空字节处理安全绕过漏洞
漏洞版本: PHP 5.3.27 PHP 5.4.17 PHP 5.5.1 漏洞描述: Bugtraq ID:61776 PHP是一种HTML内嵌式的脚本语言 PHP SSL模块不正确处理服务器SSL ...
- centos6.5 设置静态ip地址
vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0BOOTPRO ...
- 使用Sql按日期条件查询
--查询当天(1: select * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 --查询当天(2:select * from i ...