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 思路: 之前用 ...
随机推荐
- 斯坦福第二课:单变量线性回归(Linear Regression with One Variable)
二.单变量线性回归(Linear Regression with One Variable) 2.1 模型表示 2.2 代价函数 2.3 代价函数的直观理解 I 2.4 代价函数的直观理解 I ...
- Using RUNDLL32.exe to call a function within a dll
Using RUNDLL32.exe to call a function within a dll Rundll32 is a utility included with Window ...
- Magento 本地搬家至网络服务器步骤
1.将本地的Magento的数据库备份下来. 2.将本地的Magento网站资料做成ZIP资料. 3.将Magento网站 ZIP资料上传到服务器的域名指向的资料夹内. 4.将ZIP解压出来,移动到域 ...
- PKU 1573 Robot Motion(简单模拟)
原题大意:原题链接 给出一个矩阵(矩阵中的元素均为方向英文字母),和人的初始位置,问是否能根据这些英文字母走出矩阵.(因为有可能形成环而走不出去) 此题虽然属于水题,但是完全独立完成而且直接1A还是很 ...
- 404 Not Found 探秘Nginx转发处理流程
一.问题描述 访问一个链接地址后报404 Not Found nginx/1.10.2 1 112.95.211.154 - - [08/Mar/2018:15:22:21 +0800] " ...
- redis 慢查询日志
说明:针对慢查询日志,可以设置两个参数,一个是执行时长,单位为微秒,另一个是慢查询日志的长度.如果超过该长度,当一个新的命令被写入日志时,最老的一条会从命令日志队列中被移除. 编辑配置文件redis. ...
- NRF24L01——工作原理解读
源: NRF24L01——工作原理解读
- platform_device和platform_driver的注册过程,及probe函数何时调用的分析 ⭐⭐⭐
add platform_device之后,需要注意的一个地方是这里,add是通过系统初始化里边调用platform_add_devices把所有放置在板级platform_device数组中的所有 ...
- MySQL——修改数据表
1.添加单列: ALERT TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST|AFTER col_name 其中tbl_nam ...
- JAVA链接数据库
链接:http://www.cnblogs.com/centor/p/6142775.html 开发工具: MyEclipse MySQL JDBC驱动:mysql-connector-java-5. ...