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

Problem Description
Mario 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.
 
Input
The first line follows an integer T, the number of test data.

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.)
 
Output
For 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.
 
Sample Input
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
 
Sample Output
Case 1:
4
0
0
3
1
2
0
1
5
1
 
Source

题意: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 树阵离线/划分树的更多相关文章

  1. BZOJ 3626 [LNOI2014]LCA 树剖+(离线+线段树 // 在线+主席树)

    BZOJ 4012 [HNOI2015]开店 的弱化版,离线了,而且没有边权(长度). 两种做法 1 树剖+离线+线段树 这道题求的是一个点zzz与[l,r][l,r][l,r]内所有点的lcalca ...

  2. hdu-4417 Super Mario(树状数组 + 划分树)

    题目链接: Super Mario Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU-4417 Super Mario,划分树+二分!

    Super Mario 这个题也做了一天,思路是很清晰,不过二分那里写残了,然后又是无限RE.. 题意:就是查询区间不大于k的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...

  4. ACM学习历程—HDU4417 Super Mario(树状数组 && 离线)

    Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping ability re ...

  5. HDU4417 Super Mario(主席树)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4417 Description Mario is world-famous plumber. ...

  6. hdu4417 Super Mario (树状数组/分块/主席树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个长度为n的序列,有m个询问,每次询问包含l,r,h,即询问区间[l,r]小于等 ...

  7. HDU4417 - Super Mario(主席树)

    题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...

  8. [HDU4417]Super Mario(主席树+离散化)

    传送门 又是一道主席树模板题,注意数组从0开始,还有主席树耗费空间很大,数组开大点,之前开小了莫名其妙TLE.QAQ ——代码 #include <cstdio> #include < ...

  9. HDU--4417 Super Mario (主席树模版题)

    题目链接 题目让求 L R区间 不大于H 的数有多少 数据太大需要离散化 #include<bits/stdc++.h> using namespace std; #define maxn ...

随机推荐

  1. IOS总结_IOS经常使用的方法集合、调用系统电话、设备区分、APP内永不锁屏

    调用系统打电话的功能 打电话功能仅仅有iPhone支持,对于其它设备相应button应该禁用. //直接调用系统电话呼叫功能,挂断电话后不能回到应用程序 [UIApplication sharedAp ...

  2. adp设备是什么

    今天在写软工文档的可行性分析部分的时候.遇到一个新名词--adp,瞬间就不淡定了.原话例如以下: 6.1.1 基本建设投资 包含採购.开发和安装下列各项所需的费用,如: a. 须要提供一件教室,供开发 ...

  3. (二)给IE6-IE9中的input添加HTML5新属性-placeholder

    同样是最近遇到的一个小问题.因为IE9以下input是不支持placeholder属性的.在网上找到了解决方案,果断带走.正如鲁迅先生所说的‘拿来主义’:运用脑髓,放出眼光,自己来拿!感谢.借花献佛在 ...

  4. [Sqlite] --&gt; Sqlite于Windows、Linux 和 Mac OS X 在安装过程

    一个:于 Windows 安装 SQLite  1,下载 请訪问SQLite下载页面http://www.sqlite.org/download.html.从Windows 区下载预编译的二进制文件. ...

  5. Install Typical IIS Workloads

    原文 Install Typical IIS Workloads Introduction The IIS 7.0 and above modular architecture is designed ...

  6. Oracle 数据导出到PowerDesigner

    原文:Oracle 数据导出到PowerDesigner [一]配置ODBC win7 :控制面板(查看方式:小图标)→管理工具→数据源(ODBC) 在[ODBC数据源管理器]面板下,在默认[用户DN ...

  7. log4j+logback+slf4j+commons-logging的关系与调试(转)

    背景     由于现在开源框架日益丰富,好多开源框架使用的日志组件不尽相同.存在着在一个项目中,不同的版本,不同的框架共存.导致日志输出异常混乱.虽然也不至于对系统造成致命伤害,但是明显可以看出,架构 ...

  8. JavaScript中null和undefined的总结

    先说null,它表示一个特殊值,常用来描述“空值”.对null执行typeof运算,结果返回字符串“object”,也就是说,可以将null认为是一个特殊的对象值,含义是“非对象”(感觉怪怪的).实际 ...

  9. Python 基于学习 网络小爬虫

    <span style="font-size:18px;"># # 百度贴吧图片网络小爬虫 # import re import urllib def getHtml( ...

  10. XP下类似%windir% %userprofile% 的变量的说明(转)

    在一些批处理或者系统技巧操作教程文章中,我们常常会看到一些形如 %windir% 或者 %systemdrive% 的变量.这些变量都代表着什么含义呢?下面小技巧之家为大家整理了在Windows XP ...