hdu4417 Super Mario
Problem Description
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.)
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
正解:主席树
建立从1-i的线段树,每次查询时比较r与l-1之差,如果mid<=H则往左查询,否则往右查询,并加上sum[ls[y]]-sum[ls[x]],查询到叶子时也把两者之差加上。
//It is made by wfj_2048~
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define inf 1<<30
#define il inline
#define RG register
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout) using namespace std; int sum[],ls[],rs[],root[],num[],a[],hashh[],n,m,sz,tot; il int gi(){
RG int x=,q=; RG char ch=getchar(); while ((ch<'' || ch>'') && ch!='-') ch=getchar();
if (ch=='-') q=,ch=getchar(); while (ch>='' && ch<='') x=x*+ch-,ch=getchar(); return q ? -x : x;
} il void insert(RG int x,RG int &y,RG int l,RG int r,RG int v){
y=++sz,sum[y]=sum[x]+,ls[y]=ls[x],rs[y]=rs[x]; if (l==r) return; RG int mid=(l+r)>>;
if (v<=mid) insert(ls[x],ls[y],l,mid,v); else insert(rs[x],rs[y],mid+,r,v);
} il int query(RG int x,RG int y,RG int l,RG int r,RG int v){
if (l==r) return sum[y]-sum[x]; RG int mid=(l+r)>>;
if (v<=mid) return query(ls[x],ls[y],l,mid,v);
else return sum[ls[y]]-sum[ls[x]]+query(rs[x],rs[y],mid+,r,v);
} il void work(){
n=gi(),m=gi(); for (RG int i=;i<=n;++i) num[i]=a[i]=gi(); sort(num+,num+n+);
hashh[++tot]=num[]; for (RG int i=;i<=n;++i) if (num[i]!=num[i-]) hashh[++tot]=num[i];
for (RG int i=;i<=n;++i) insert(root[i-],root[i],,tot,lower_bound(hashh+,hashh+tot+,a[i])-hashh);
for (RG int i=;i<=m;++i){
RG int l=gi()+,r=gi()+,h=gi(),H=upper_bound(hashh+,hashh+tot+,h)-hashh-;
if (!H) printf("0\n"); else printf("%d\n",query(root[l-],root[r],,tot,H));
}
return;
} int main(){
File("hdu4417");
RG int T=gi();
for (RG int i=;i<=T;++i){ sz=tot=; printf("Case %d:\n",i); work(); }
return ;
}
hdu4417 Super Mario的更多相关文章
- hdu4417 Super Mario 树阵离线/划分树
http://acm.hdu.edu.cn/showproblem.php?pid=4417 Super Mario Time Limit: 2000/1000 MS (Java/Others) ...
- hdu-4417 Super Mario(树状数组 + 划分树)
题目链接: Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU-4417 Super Mario,划分树+二分!
Super Mario 这个题也做了一天,思路是很清晰,不过二分那里写残了,然后又是无限RE.. 题意:就是查询区间不大于k的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...
- HDU4417 Super Mario(主席树)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4417 Description Mario is world-famous plumber. ...
- ACM学习历程—HDU4417 Super Mario(树状数组 && 离线)
Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...
- HDU4417 - Super Mario(主席树)
题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...
- HDU--4417 Super Mario (主席树模版题)
题目链接 题目让求 L R区间 不大于H 的数有多少 数据太大需要离散化 #include<bits/stdc++.h> using namespace std; #define maxn ...
- [HDU4417]Super Mario(主席树+离散化)
传送门 又是一道主席树模板题,注意数组从0开始,还有主席树耗费空间很大,数组开大点,之前开小了莫名其妙TLE.QAQ ——代码 #include <cstdio> #include < ...
- hdu4417 Super Mario (树状数组/分块/主席树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个长度为n的序列,有m个询问,每次询问包含l,r,h,即询问区间[l,r]小于等 ...
随机推荐
- Pydev--unresolved import:解决办法
1.右键点击项目,选择Properties-->Pydev-Interpreter/Grammar 2.点击"Click here to configure an interprete ...
- 跑马灯、短信与反射EditText
1.1.跑马灯功能 Android自带支持跑马灯功能,实现此功能需要设置已下属性: android:ellipsize="marquee" // 必选,跑马灯样式 android: ...
- 手动编写JQUERY插件
就拿一个简单的示例来说,鼠标点击输入框,提示文字消息,鼠标移开,再显示提示文字. <script type="text/javascript"> //编写插件 (fun ...
- Linux之nc命令详解
nc是一个强大的网络工具,可以通过yum安装 [root@LB2 ~]# which nc /usr/bin/which: no nc in (/usr/local/sbin:/usr/local/b ...
- Memcached十问十答
1.Memcached是什么,有什么作用? Memcached是一种纯内存的,key-value,CS架构的数据库服务软件,主要用于数据库,web服务器的缓存,以减小数据库,web服务器的访问压力,尤 ...
- Linux之uniq命令
uniq - report or omit repeated lines 省去重复的行 参数: -i 忽略大小写字符的不同 -c 对重复的行进行记数 注意:uniq命令只会对相邻的重复的行进行去 ...
- deepin系统下如何设置wifi热点(亲测有效)
deepin系统下如何设置wifi热点(亲测有效) deepin wifi ap linux 热点 首先必须吐槽一下linux下设置wifi太累了....来来回回折腾了我好久的说.心累... 好了废话 ...
- 浅谈MVC缓存
缓存是将信息放在内存中以避免频繁访问数据库从数据库中提取数据,在系统优化过程中,缓存是比较普遍的优化做法和见效比较快的做法. 对于MVC有Control缓存和Action缓存. 一.Control缓存 ...
- win32 htmlayout点击按钮创建新窗口,以及按钮图片样式
最近在做一个C++ win32的桌面图形程序,我不是C++程序员,做这个只是因为最近没什么java的活. windows api,之前接触的时候,还是大学,那时用这个开发打飞机游戏纯粹是娱乐.现在基本 ...
- sql server删除主键约束所想到的
从网上找到了下面一段代码: declare @Pk varchar(100);select @Pk=Name from sysobjects where Parent_Obj=OBJECT_ID('表 ...