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.

InputThe 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.)OutputFor 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 给出 n 个数,m个询问,对于每个询问,求出在区间[l, r]内小于等于 h 的数的个数。
主席树的模板题,数很大,所以需要离散化一下,维护前缀个数和。
查询的时候先找到第一个小于等于 h 的离散化后对应的下标,利用主席树找区间内值小于等于 k 的数的和。
 /*
.
';;;;;.
'!;;;;;;!;`
'!;|&#@|;;;;!:
`;;!&####@|;;;;!:
.;;;!&@$$%|!;;;;;;!'.`:::::'.
'!;;;;;;;;!$@###&|;;|%!;!$|;;;;|&&;.
:!;;;;!$@&%|;;;;;;;;;|!::!!:::;!$%;!$%` '!%&#########@$!:.
;!;;!!;;;;;|$$&@##$;;;::'''''::;;;;|&|%@$|;;;;;;;;;;;;;;;;!$;
;|;;;;;;;;;;;;;;;;;;!%@#####&!:::;!;;;;;;;;;;!&####@%!;;;;$%`
`!!;;;;;;;;;;!|%%|!!;::;;|@##%|$|;;;;;;;;;;;;!|%$#####%;;;%&;
:@###&!:;;!!||%%%%%|!;;;;;||;;;;||!$&&@@%;;;;;;;|$$##$;;;%@|
;|::;;;;;;;;;;;;|&&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;;;;;%$!:''''''':|%!;;;;;;;;|&@%||` '%$|!%&;
|@%!;;!!;;;||;:'''''':;%$!;;;;!%%%&#&%$&: .|%;:!&%`
!@&%;;;;;;;||;;;:''::;;%$!;;;;;;;|&@%;!$; `%&%!!$&:
'$$|;!!!!;;||;;;;;;;;;;%%;;;;;;;|@@|!$##; !$!;:!$&:
|#&|;;;;;;!||;;;;;;;;!%|;;;;!$##$;;;;|%' `%$|%%;|&$'
|&%!;;;;;;|%;;;;;;;;$$;;;;;;|&&|!|%&&; .:%&$!;;;:!$@!
`%#&%!!;;;;||;;;;;!$&|;;;!%%%@&!;;;!!;;;|%!;;%@$!%@!
!&!;;;;;;;;;||;;%&!;;;;;;;;;%@&!;;!&$;;;|&%;;;%@%`
'%|;;;;;;;;!!|$|%&%;;;;;;;;;;|&#&|!!||!!|%$@@|'
.!%%&%'`|$; :|$#%|@#&;%#%.
*/
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lowbit(x) x & (-x)
#define mes(a, b) memset(a, b, sizeof a)
#define fi first
#define se second
#define pii pair<int, int>
#define INOPEN freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e5 + ;
const int maxm = 1e5 + ;
const int mod = 1e9 + ;
const ll INF = 1e18 + ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
using namespace std; int n, m;
int cas, tol, T; struct Node {
int l, r;
int sum;
} node[maxn * ];
int a[maxn];
int rt[maxn];
vector<int> vv; void init() {
tol = ;
mes(rt, );
vv.clear();
} int getid(int x) {
return lower_bound(vv.begin(), vv.end(), x) - vv.begin() + ;
} void update(int l, int r, int &x, int y, int pos) {
tol++;
node[tol] = node[y];
node[tol].sum ++;
x = tol;
if(l == r) return ;
int mid = (l + r) >> ;
if(pos <= mid)
update(l, mid, node[x].l, node[y].l, pos);
else
update(mid+, r, node[x].r, node[y].r, pos);
} int query(int l, int r, int x, int y, int pos) {
if(l == r) {
if(l <= pos)
return node[y].sum - node[x].sum;
else
return ;
}
if(r <= pos)
return node[y].sum - node[x].sum;
int mid = (l +r) >> ;
if(pos <= mid)
return query(l, mid, node[x].l, node[y].l, pos);
else {
int tmp = node[node[y].l].sum - node[node[x].l].sum;
return tmp + query(mid+, r, node[x].r, node[y].r, pos);
}
} int main() {
cas = ;
scanf("%d", &T);
while(T--) {
init();
scanf("%d%d", &n, &m);
for(int i=; i<=n; i++) {
scanf("%d", &a[i]);
vv.push_back(a[i]);
}
sort(vv.begin(), vv.end());
vv.erase(unique(vv.begin(), vv.end()), vv.end());
for(int i=; i<=n; i++) {
int id = getid(a[i]);
update(, n, rt[i], rt[i-], id);
}
printf("Case %d:\n", cas++);
while(m--) {
int u, v, d;
scanf("%d%d%d", &u, &v, &d);
u++, v++;
int id = getid(d);
if(vv[id-] != d)
id--;
int ans = query(, n, rt[u-], rt[v], id);
printf("%d\n", ans);
}
}
return ;
}

Super Mario HDU - 4417 (主席树)的更多相关文章

  1. Super Mario HDU 4417 主席树区间查询

    Super Mario HDU 4417 主席树区间查询 题意 给你n个数(编号从0开始),然后查询区间内小于k的数的个数. 解题思路 这个可以使用主席树来处理,因为这个很类似查询区间内的第k小的问题 ...

  2. Super Mario HDU - 4417 (主席树询问区间比k小的个数)

    Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...

  3. J - Super Mario HDU - 4417 线段树 离线处理 区间排序

    J - Super Mario HDU - 4417 这个题目我开始直接暴力,然后就超时了,不知道该怎么做,直接看了题解,这个习惯其实不太好. 不过网上的思路真的很厉害,看完之后有点伤心,感觉自己应该 ...

  4. AC日记——Super Mario hdu 4417

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDU 4417 主席树写法

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. hdu 5919 主席树(区间不同数的个数 + 区间第k大)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  7. hdu4417(Super Mario)—— 二分+划分树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. HDU 2852 主席树

    KiKi's K-Number Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. HDU 2655 主席树

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. PJSIP 自动化测试工具安装 Python安装

    Python安装,记录步骤如下 1.下载PythonIDE安装包 到官网 https://repo.continuum.io/archive/下载需要的版本,选择的Anaconda版本3的,当然也可以 ...

  2. 我现在有个表,里面有100个不同的单词,每个单词对应有大概20个词组,我想通过sql,每个单词随机获取对应的3个词组,请问怎么写可以实现?

    闲来无事刷技术论坛,看到一个这样的问题: 我现在有个表,里面有100个不同的单词,每个单词对应有大概20个词组,我想通过sql,每个单词随机获取对应的3个词组,请问怎么写可以实现? 感觉题材很新颖,角 ...

  3. c/c++ 网络编程 UDP 改变网卡的硬件地址

    网络编程 UDP 改变网卡的硬件地址 在程序里动态改变网卡的硬件地址 1,取得网卡的硬件地址 #include <stdio.h> #include <string.h> #i ...

  4. Bootstrap -- 网格系统、排版样式类、 <blockquote>、 <abbr> 元素

    Bootstrap -- 网格系统.排版样式类. <blockquote>. <abbr> 元素 1. Bootstrap 提供了一套响应式.移动设备优先的流式网格系统,随着屏 ...

  5. Visual Studio 2017的安装与使用

    Visual Studio 2017的安装与使用 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. 下载Visual Studio 2017 在官网 ...

  6. TypeScript——初步认识

    JavaScript的痛点 众所周知,前端开发“三剑客”分别是HTML.CSS以及JS,其中JS由于其灵活简单等特点获得了大家的青睐,但是成也萧何败萧何,由于JS设计初衷是浏览器的嵌入式脚本语言,作为 ...

  7. Git命令行管理代码、安装及使用

    出处:https://www.cnblogs.com/ximiaomiao/p/7140456.html Git安装和使用     目的:通过Git管理github托管项目代码 一.下载安装Git 1 ...

  8. display:inline-block,block,inline的区别与用法

    一.首先要了解什么是块级元素与行级元素 块级元素 会占领页面的一行,其后多个block元素自动换行. 可以设置width,height,设置了width后同样也占领一行.同样也可以设置   margi ...

  9. 使用CompletableFuture优化你的代码执行效率

    这篇文章详细讲解java8中CompletableFuture的特性,方法以及实例. 在java8以前,我们使用java的多线程编程,一般是通过Runnable中的run方法来完成,这种方式,有个很明 ...

  10. top 自动执行的shell脚本中,使用top -n 1 > log.txt, 上电自动执行,文件无输出

    . 自动执行的shell脚本中,使用top -n > log.txt, 上电自动执行,文件无输出,使用一下命令解决: //usr/bin/top -d -n -b > log.txt 如果 ...