题目链接:

Super Mario

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 32768/32768 K (Java/Others)

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
 
题意:
 
给定一个数列.给区间[l,r]问此区间内<=k的数目是多少;
 
 
思路:
 
可以用树状数组离线处理,把原序列按从小到大排序,询问也按k的大小排序,然后一边询问一边update;最近学了划分树,也可以做这题,看明天有时间想一想怎么做吧;
 
AC代码:
 
/*
树状数组的代码:
4417 202MS 3744K 1873 B G++ 2014300227 */ #include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N],n,m,sum[N],ans[N];
struct node
{
friend bool operator< (node x,node y)
{
if(x.num == y.num)return x.pos < y.pos;
return x.num < y.num;
}
int l,r,pos,num;
};
node po[N];
struct nod
{
friend bool operator< (nod x,nod y)
{
if(x.a==y.a)return x.pos<y.pos;
return x.a<y.a;
}
int a,pos;
};
nod p[N];
int lowbit(int x)
{
return x&(-x);
}
void update(int x)
{
while(x<=n)
{
sum[x]++;
x+=lowbit(x);
}
}
int query(int x)
{
int s=;
while(x>)
{
s+=sum[x];
x-=lowbit(x);
}
return s;
}
int main()
{
int t;
scanf("%d",&t);
int cnt=;
while(t--)
{
memset(sum,,sizeof(sum));
printf("Case %d:\n",cnt++);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&p[i].a);
p[i].pos=i;
}
sort(p+,p+n+);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&po[i].l,&po[i].r,&po[i].num);
po[i].l++;
po[i].r++;
po[i].pos=i;
}
sort(po,po+m);
int fp=;
for(int i=;i<m;i++)
{
if(p[fp].a<=po[i].num)
{
while(p[fp].a<=po[i].num&&fp<=n)
{
update(p[fp].pos);
fp++;
}
}
if(po[i].l==)ans[po[i].pos]=query(po[i].r);
else
{
ans[po[i].pos]=query(po[i].r)-query(po[i].l-);
}
}
for(int i=;i<m;i++)
{
printf("%d\n",ans[i]);
} } return ;
}

hdu-4417 Super Mario(树状数组 + 划分树)的更多相关文章

  1. hdu 1166:敌兵布阵(树状数组 / 线段树,入门练习题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. 树状数组 && 线段树应用 -- 求逆序数

    参考:算法学习(二)——树状数组求逆序数 .线段树或树状数组求逆序数(附例题) 应用树状数组 || 线段树求逆序数是一种很巧妙的技巧,这个技巧的关键在于如何把原来单纯的求区间和操作转换为 求小于等于a ...

  3. hdu1394(枚举/树状数组/线段树单点更新&区间求和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给出一个循环数组,求其逆序对最少为多少: 思路:对于逆序对: 交换两个相邻数,逆序数 +1 ...

  4. 【BZOJ-1452】Count 树状数组 套 树状数组

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1769  Solved: 1059[Submit][Stat ...

  5. zoj2112 树状数组+主席树 区间动第k大

    Dynamic Rankings Time Limit: 10000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Subm ...

  6. BZOJ_1901_Zju2112 Dynamic Rankings_树状数组+主席树

    BZOJ_1901_Zju2112 Dynamic Rankings_树状数组+主席树 题意: 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i, ...

  7. Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分)

    Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分) Description L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之 ...

  8. 洛谷P2414 阿狸的打字机 [NOI2011] AC自动机+树状数组/线段树

    正解:AC自动机+树状数组/线段树 解题报告: 传送门! 这道题,首先想到暴力思路还是不难的,首先看到y有那么多个,菜鸡如我还不怎么会可持久化之类的,那就直接排个序什么的然后按顺序做就好,这样听说有7 ...

  9. 【BZOJ】1047: [HAOI2007]理想的正方形(单调队列/~二维rmq+树状数组套树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1047 树状数组套树状数组真心没用QAQ....首先它不能修改..而不修改的可以用单调队列做掉,而且更 ...

随机推荐

  1. MySQL -进阶

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用 SELECT * FROM(SELE ...

  2. 浅谈js中的MVC

    MVC是什么? MVC是一种架构模式,它将应用抽象为3个部分:模型(数据).视图.控制器(分发器) 本文将用一个经典的例子todoList来展开 一个事件发生的过程(通信单向流动): 1.用户在视图V ...

  3. python实现区块链代码

    如果你明白了原理其实挺简单的. 加密算法是python自带的 需要导入hashlib import hashlib as hash sha = hasher.sha256() sha.update(' ...

  4. typedef struct与struct定义结构体

    今天在定义结构体的时候发现typedef struct与struct定义结构体有一些不同之处: 结构也是一种数据类型, 能够使用结构变量, 因此,  象其他 类型的变量一样, 在使用结构变量时要先对其 ...

  5. c#中Monitor的使用

    首先lock和Minitor有什么区别呢? 其实lock在IL代码中会被翻译成Monitor.也就是Monitor.Enter(obj)和Monitor.Exit(obj). lock(obj) { ...

  6. C#中web.config文件详解

    C#中web.config文件详解 一.认识Web.config文件 Web.config 文件是一个XML文本文件,它用来储存 ASP.NET Web 应用程序的配置信息(如最常用的设置ASP.NE ...

  7. java中BigDecimal的学习

    干着java的活,但是看的都是一些偏底层的东西(或者我根本就没有看),有点荒废了java的学习. 最近一直在用到一个类是BigDecimal,但都是模棱两可地在那儿用,并没有深入研究这个类的细节,感觉 ...

  8. zeroMQ研究(转)

    偶尔一个机会,了解了下zeroMQ消息队列. 1  ZeroMQ概述 ZeroMQ是一种基于消息队列的多线程网络库,其对套接字类型.连接处理.帧.甚至路由的底层细节进行抽象,提供跨越多种传输协议的套接 ...

  9. 目标检测之vibe---ViBe(Visual Background extractor)背景建模或前景检测

    ViBe算法:ViBe - a powerful technique for background detection and subtraction in video sequences 算法官网: ...

  10. 用canvas合成图片

    朋友圈有些分享功能是通过长按图片另存来实现的,就像淘宝内部要分享朋友圈的时候一样,这些图片可以用canvas来合成. 获取了img的dom对象以后,进行base64的转. //加载对象$page.ge ...