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]小于等 ...
随机推荐
- JavaWeb从0开始学(二)-----JSP基本语法与编译指令
在上一节中我们学习了如何搭建一个简单的Web应用,并且已经知晓了一个JSP页面主要由静态的HTML内容和动态的Java脚本共同组成.JSP的基本语法共有JSP注释.JSP声明.输出JSP表达式与JSP ...
- linux下mysql的大小写是否区分设置
转:http://blog.csdn.net/qq_29246225/article/details/52293549 一.Linux中MySQL大小写详情:1.数据库名严格区分大小写2.表名严格区分 ...
- Java基础——深入理解Java中的final关键字(转载)
Java中的final关键字非常重要,它可以应用于类.方法以及变量.这篇文章中我将带你看看什么是final关键字?将变量,方法和类声明为final代表了什么?使用final的好处是什么?最后也有一些使 ...
- C#生成漂亮验证码完整代码类
using System;using System.Web;using System.Drawing;using System.Security.Cryptography; namespace Dot ...
- Spring+SpringMVC+MyBatis+easyUI整合优化篇(二)Log4j讲解与整合
日常啰嗦 上一篇文章主要讲述了一下syso和Log间的一些区别与比较,重点是在项目的日志功能上,因此,承接前文<Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)Sy ...
- Python之路-awk文本处理
作业一:整理博客,内容包含awk.变量.运算符.if多分支 一.awk 1.awk是一个优秀的文本处理工具,多用来处理含有特殊分隔符的内容 常见用法 awk -F: {print $1,$4} 作业 ...
- 老李推荐:第14章9节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-遍历控件树查找控件
老李推荐:第14章9节<MonkeyRunner源码剖析> HierarchyViewer实现原理-遍历控件树查找控件 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员 ...
- poptest分享计划以及提供的服务
poptest分享计划以及提供的服务 POPTEST致力于测试开发工程师的培养,能让学员经过系统培训后从事自动化测试工作,包括功能自动化.性能自动化.接口自动化以及移动端系统的自动化测试等,由于移动端 ...
- number问题
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one ...
- C# Task 源代码阅读(1)
平时我们开发中,经常使用Task,后续的.net版本种很多都和Task有关,比如asyn,await有了Task 我们很少就去关注Thread 了.Task 给我们带来了很多的便利之处.是我们更少的去 ...