HDU 4417 BIT or ST
Super Mario
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6804    Accepted Submission(s): 2920
is world-famous plumber. His “burly” figure and amazing jumping ability
reminded in our memory. Now the poor princess is in trouble again and
Mario needs to save his lover. We regard the road to the boss’s castle
as a line (the length is n), on every integer point i there is a brick
on height hi. Now the question is how many bricks in [L, R] Mario can
hit if the maximal height he can jump is H.
For each test data:
The
first line contains two integers n, m (1 <= n <=10^5, 1 <= m
<= 10^5), n is the length of the road, m is the number of queries.
Next line contains n integers, the height of each brick, the range is [0, 1000000000].
Next m lines, each line contains three integers L, R,H.( 0 <= L <= R < n 0 <= H <= 1000000000.)
each case, output "Case X: " (X is the case number starting from 1)
followed by m lines, each line contains an integer. The ith integer is
the number of bricks Mario can hit for the ith query.
10 10
0 5 2 7 5 4 3 8 7 7
2 8 6
3 5 0
1 3 1
1 9 4
0 1 0
3 5 5
5 5 1
4 6 3
1 5 7
5 7 3
4
0
0
3
1
2
0
1
5
1
/*树状数组*/
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MAXN (100000+15)
int C[MAXN];
inline int lowbit(int x){return x&-x;}
inline int sum(int x)
{
int ret=;
for(;x;x-=lowbit(x)) ret+=C[x];
return ret;
}
inline void add(int x,int d,int n)
{
while(x<=n){
C[x]+=d;
x+=lowbit(x);
}
}
struct node
{
int l,r,h,id,ans;
}P[MAXN];
bool cmpid(node A,node B){return A.id<B.id;}
bool cnph(node A,node B){return A.h<B.h;}
struct node2
{
int h,id;
bool operator<(const node2& x)const{
return h<x.h;}
}Q[MAXN];
int main()
{
int t,n,m,i,j,k=,s;
scanf("%d",&t);
for(k=;k<=t;++k)
{
memset(C,,sizeof(C));
scanf("%d%d",&n,&m);
for(i=;i<=n;++i) scanf("%d",&Q[i].h),Q[i].id=i;
sort(Q+,Q++n);
for(i=;i<=m;++i)
{
scanf("%d%d%d",&P[i].l,&P[i].r,&P[i].h);
P[i].l++;
P[i].r++;
P[i].id=i;
}
printf("Case %d:\n",k);
sort(P+,P++m,cnph);
for(i=,j=;i<=m;++i)
{
while(j<=n&&Q[j].h<=P[i].h) add(Q[j++].id,,n);
P[i].ans=sum(P[i].r)-sum(P[i].l-);
}
sort(P+,P++m,cmpid);
for(i=;i<=m;++i)
printf("%d\n",P[i].ans);
}
return ;
} /* 线段树*/
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define lc (id<<1)
#define rc (id<<1|1)
#define M ((L+R)>>1)
int C[(MAXN<<)+];
void update(int L,int R,int id,int x)
{
if(L==R){C[id]++;return;}
if(x<=M) update(L,M,lc,x);
else update(M+,R,rc,x);
C[id]=C[lc]+C[rc];
}
int query(int L,int R,int id,int l,int r)
{
if(L>=l&&R<=r){return C[id];}
if(r<=M) return query(L,M,lc,l,r);
else if(l>M) return query(M+,R,rc,l,r);
else return query(L,M,lc,l,r)+query(M+,R,rc,l,r);
}
struct node
{
int l,r,h,id,ans;
}P[MAXN+];
bool cmpid(node A,node B){return A.id<B.id;}
bool cmph(node A,node B){return A.h<B.h;}
struct node2
{
int h,id;
bool operator<(const node2&x)const{return h<x.h;}
}Q[MAXN+];
int main()
{
int t,i,j,n,m,k=;
scanf("%d",&t);
for(k=;k<=t;++k)
{
scanf("%d%d",&n,&m);
for(i=;i<=n;++i) scanf("%d",&Q[i].h),Q[i].id=i;
sort(Q+,Q++n);
for(i=;i<=m;++i)
{
scanf("%d%d%d",&P[i].l,&P[i].r,&P[i].h);
P[i].l++;
P[i].r++;
P[i].id=i;
}
sort(P+,P++m,cmph);
for(i=,j=;i<=m;++i)
{
while(j<=n&&Q[j].h<=P[i].h){update(,n,,Q[j].id);j++;}
P[i].ans=query(,n,,P[i].l,P[i].r);
}
sort(P+,P++m,cmpid);
printf("Case %d:\n",k);
for(i=;i<=m;++i) printf("%d\n",P[i].ans);
memset(C,,sizeof(C));
}
return ;
}
HDU 4417 BIT or ST的更多相关文章
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
		Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ... 
- Super Mario HDU 4417 主席树区间查询
		Super Mario HDU 4417 主席树区间查询 题意 给你n个数(编号从0开始),然后查询区间内小于k的数的个数. 解题思路 这个可以使用主席树来处理,因为这个很类似查询区间内的第k小的问题 ... 
- J - Super Mario HDU - 4417  线段树 离线处理 区间排序
		J - Super Mario HDU - 4417 这个题目我开始直接暴力,然后就超时了,不知道该怎么做,直接看了题解,这个习惯其实不太好. 不过网上的思路真的很厉害,看完之后有点伤心,感觉自己应该 ... 
- HDU 4417 (划分树+区间小于k统计)
		题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个区间,以及一个k值,求该区间内小于等于k值的数的个数.注意区间是从0开始的 ... 
- HDU 4417:Super Mario(主席树)
		http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意是:给出n个数和q个询问,每个询问有一个l,r,h,问在[l,r]这个区间里面有多少个数是小于等于h的 ... 
- [HDU 4417] Super Mario (树状数组)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给你n个数,下标为0到n-1,m个查询,问查询区间[l,r]之间小于等于x的数有多少个 ... 
- hdu 4417 Super Mario/树套树
		原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意很简单,给定一个序列求一个区间 [L, R,]中小于等于H的元素的个数. 好像函数式线段树可 ... 
- HDU 5875 Function(ST表+二分)
		[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5875 [题目大意] 给出一个数列,同时给出多个询问,每个询问给出一个区间,要求算出区间从左边开始不 ... 
- hdu 4417 Super Mario (主席树)
		链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ... 
随机推荐
- JAVA中重写equals()方法为什么要重写hashcode()方法?
			object对象中的 public boolean equals(Object obj),对于任何非空引用值 x 和 y,当且仅当 x 和 y 引用同一个对象时,此方法才返回 true:注意:当此方法 ... 
- SqlServer中创建Oracle链接服务器
			SqlServer中创建Oracle链接服务器 第一种:界面操作 (1)展开服务器对象-->链接服务器-->右击“新建链接服务器” (2)输入链接服务器的IP (3)链接成功后 第二种:语 ... 
- Java程序运行在Docker等容器环境有哪些新问题
			基本回答 一. 对于Java来说,Docker毕竟是一个较新的环境,其内存.CPU等资源限制是通过ControlGroup实现的.早期的JDK版本并不能识别这些限制,进而会导致一些基础问题. 1.如 ... 
- intellij-idea打包Scala代码在spark中运行
			.创建好Maven项目之后(记得添加Scala框架到该项目),修改pom.xml文件,添加如下内容: <properties> <spark.version></spar ... 
- Openwrt架设GIT服务
			#下载宝刷LEDE版系统后, 在上面安装git包 opkg update opkg install git #安装好后在将git仓库装到SD(TF)卡上 #用fdisk对SD 卡分区 #fdisk / ... 
- 2009-2010 ACM-ICPC, NEERC, Western Subregional Contest
			2009-2010 ACM-ICPC, NEERC, Western Subregional Contest 排名 A B C D E F G H I J K L X 1 0 1 1 1 0 1 X ... 
- 构造函数挨个过 —— String()
			本篇整理JavaScript中构造函数String的相关知识,主要分为以下三个部分: 构造函数String()的作用与使用方式: String()的属性和方法: 字符串对象实例属性和方法: 一 构造函 ... 
- Tomcat access log配置(二)
			前次讨论了spring boot 中添加Tomcat access log 是轻松愉快,配置文件中添加server.tomcat.accesslog即可,那么如果是外置的Tomcat容器又该如何配置呢 ... 
- Mysql  MariaDB安装
			1.安装 本人使用的是CentOS 7 ,默认yum安装,但默认yum安装版本有点低,可根据需要选择升级,我这里选择先升级再安装. 更新yum //更新yum包 yum -y update 配置yum ... 
- 【pytorch】pytorch基础学习
			目录 1. 前言 # 2. Deep Learning with PyTorch: A 60 Minute Blitz 2.1 base operations 2.2 train a classifi ... 
