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]小于等 ...
随机推荐
- python IP地址转16进制
python IP地址转16进制 第一种方法: 通过socket.inet_aton实现 import socket from binascii import hexlify ary='192.168 ...
- Python(五)编程小实例
Python(五)编程小实例 抓取网页信息,并生成txt文件内容! Python抓取网页技能--Python抓取网页就是我们常看见的网络爬虫,我们今天所要用到的就是我们Python中自带的模块,用这些 ...
- NIO(三、Channel)
目录 NIO(一.概述) NIO(二.Buffer) NIO(三.Channel) Channel 上文说了描述了Buffer的实现机制,那么这个章节就主要描述数据是如何进入缓冲区的,并且又是如何从缓 ...
- 帝国CMS万能标签的使用
标签名称: 带模板的信息调用标签[万能标签] [ecmsinfo]栏目ID/专题ID,显示条数,标题截取数,是否显示栏目名,操作类型,标签模板ID,只显示有标题图片[/ecmsinfo] 说明:e ...
- Docker 使用指南 (四)—— 数据卷的使用
一.数据卷的使用 有时候需要使用数据库,但是又希望它的数据能保存在本地,Docker中提供了数据卷可以供你方便的操作数据.数据卷是一个可供一个或多个容器使用的特殊目录,它绕过 UFS,可以提供很多有用 ...
- php文件基本操作与文件管理功能
文件的基本操作 先来看一下PHP文件基础操作,请看强大注释 <body> <?php var_dump(filetype("./img/11.png")); // ...
- 谈谈Backbone.js中的el
小编最近开始接触backbone.js,这个曾经非常优秀的一款MVC前端框架,在学习的过程中,遇到下图的这样一个问题 下面上代码 小编的想法很简单,只是view了一个实例,然后在initalize中调 ...
- JavaScript高级程序设计(学习)
文档模式是:混杂模式和标准模式. 若在文档开始处没有文档类型声明,则浏览器就会开启混杂模式.这种模式在不同的浏览器下行为差异非常大,如果不使用某些hack技术,跨浏览器的行为根本就没有一致性可言. 局 ...
- cuda内存总结
1.shared memory __shared__ 声明为共享内存,将会保存在共享内存中 2.constant memory __constant__ 声明为常量内存,将会保存在常量内存中,常量内 ...
- C#_扩展方法
这里我先引用一个实例,需求是这样:我们要将一个字符串中的字幕大小写变换,即大写变小写,小写变大写. 通常,我们首先会考虑在当前类中写一个方法,将字符串传进去,然后返回变换后的字符串.这样写当然不会错, ...