hdu4417 Super Mario 树阵离线/划分树
http://acm.hdu.edu.cn/showproblem.php?pid=4417
Super Mario
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2720 Accepted Submission(s): 1322
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.)
1
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
Case 1:
4
0
0
3
1
2
0
1
5
1
题意:n个数,m次询问[l,r]区间比h小于等于的数的个数。
思路:本来是个划分树裸题的。不好划分树233。可是树状数组也能够搞。
离线存进全部询问。按h大小从小到大处理每一个询问。对于每一个询问,查询[l,r]区间比h小的,事实上就是查询[1,r]区间的减去[1,l-1]区间的,我们把比h小的数先插入到树状数组中,这里是对其在原数组的位置的地方插入。然后再进行查询,就能够算出每一个询问。
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
const double eps=1e-8;
const double pi=acos(-1.0);
const int INF=0x7fffffff;
const LL inf=(((LL)1)<<61)+5;
const int N=100005;
struct node{
int l,r,val;
int id;
}q[N];
int ans[N];
int bit[N];
struct hehe{
int x,id;
}a[N];
int n,m;
bool cmp1(hehe u,hehe v)
{
return u.x<v.x;
}
bool cmp2(node u,node v)
{
return u.val<v.val;
}
int sum(int x)
{
int s=0;
while(x>0)
{
s+=bit[x];
x-=x&-x;
}
return s;
}
void add(int x,int val)
{
while(x<=n)
{
bit[x]+=val;
x+=x&-x;
}
}
int main()
{
int t,cnt=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
clr(bit);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i].x);
a[i].id=i;
}
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].val);
q[i].l++;
q[i].r++;
q[i].id=i;
}
sort(a+1,a+n+1,cmp1);
sort(q,q+m,cmp2);
int j=1;
for(int i=0;i<m;i++)
{
while(j<=n&&q[i].val>=a[j].x)
{
add(a[j].id,1);
j++;
}
ans[q[i].id]=sum(q[i].r)-sum(q[i].l-1);
}
printf("Case %d:\n",++cnt);
for(int i=0;i<m;i++)
printf("%d\n",ans[i]);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
hdu4417 Super Mario 树阵离线/划分树的更多相关文章
- BZOJ 3626 [LNOI2014]LCA 树剖+(离线+线段树 // 在线+主席树)
BZOJ 4012 [HNOI2015]开店 的弱化版,离线了,而且没有边权(长度). 两种做法 1 树剖+离线+线段树 这道题求的是一个点zzz与[l,r][l,r][l,r]内所有点的lcalca ...
- 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的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...
- ACM学习历程—HDU4417 Super Mario(树状数组 && 离线)
Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...
- HDU4417 Super Mario(主席树)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4417 Description Mario is world-famous plumber. ...
- hdu4417 Super Mario (树状数组/分块/主席树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个长度为n的序列,有m个询问,每次询问包含l,r,h,即询问区间[l,r]小于等 ...
- HDU4417 - Super Mario(主席树)
题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...
- [HDU4417]Super Mario(主席树+离散化)
传送门 又是一道主席树模板题,注意数组从0开始,还有主席树耗费空间很大,数组开大点,之前开小了莫名其妙TLE.QAQ ——代码 #include <cstdio> #include < ...
- HDU--4417 Super Mario (主席树模版题)
题目链接 题目让求 L R区间 不大于H 的数有多少 数据太大需要离散化 #include<bits/stdc++.h> using namespace std; #define maxn ...
随机推荐
- 8、Cocos2dx 3.0三,找一个小游戏开发3.0存储器管理的版本号
重开发人员的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27693365 复杂的内存管理 移动设备上的硬件资源十 ...
- 使用IronPython给.Net程序
使用IronPython给.Net程序加点料 开发的时候,经常被策划频繁变动的方案而苦恼.这时候就想要加入点动态语言来辅助一下. 在考虑用动态语言之前也曾想过使用动态加载dll的方式,实现基础接口来调 ...
- WPF学习(2)XAML
XAML(eXtensible Application Markup Language,可扩展应用程序标记语言)是一种声明式的编程语言,遵循XML的语法.WPF使用XAML来设计UI具有易用性.高效性 ...
- android 渐变drawable
渐变Drawable它是使用<gradient>的标记的形状Drawable定义子节点的定义. 每个梯度Drawable求至少要有一个startColor和endColor属性,而且支持一 ...
- 基于GeoHash算法的附近点搜索实现(一)
1. 引入 最近在参加学校的计算机仿真大赛,时间好像有点不够,所以只完成了前面的一部分最基础的功能,中途还是选择了放弃.但是之前的部分的确觉得完成得还不错,在这里分享一下.题目是要完成一个宇宙飞船加油 ...
- 不同版本的SQL Server之间数据导出导入的方法及性能比较
原文:不同版本的SQL Server之间数据导出导入的方法及性能比较 工作中有段时间常常涉及到不同版本的数据库间导出导入数据的问题,索性整理一下,并简单比较下性能,有所遗漏的方法也欢迎讨论.补充. 0 ...
- 【二分法】 HDU 2446 Shell Pyramid
意甲冠军:非常多,形成一个金字塔球 文章x层 x*(x+1)/ 2 球 给你个S 金字塔的一层代表第一数字向下S球 它是其中 这层中的第几行 第几列 公式 1 : x*(x+1)*(x+2)/ 6 ...
- linux的自动化操作相关使用方法汇总(转)
linux系统的web网站在运营状态时,我们常需要对网站进行维护,例如查看资源剩余并做出响应.日志分割.数据整理,在特定状态执行特定任务等等,这些都会需要linux能实现自动执行某些任任务.本篇博文介 ...
- React组件开发入门
React 组件开发入门 Introduction 本文组成: Ryan Clark文章Getting started with React的翻译. 博主的实践心得. React由Facebook的程 ...
- oracle当需要commit
今天oracle的SQL plus 运行该删除和查询操作,然后PL/SQL还运行查询.相同的句子,结果是不一样的.我郁闷很大,然后,突然想到这可能对双方造成由数据不一致,为什么不一致呢.就是没用com ...