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
 
 
还是用kuangbin大神的板子好 ,以后就用kuangbin大神的划分树板子算了
 
这个就把划分树的板子改一下就好了、
 
 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + ;
int a[maxn], sorted[maxn];
int num[][maxn], val[][maxn]; void build(int l, int r, int dep) {
if (l == r) return ;
int mid = (l + r) >> , same = mid - l + ;
for (int i = l ; i <= r ; i++)
if (val[dep][i] < sorted[mid]) same--;
int lpos = l, rpos = mid + ;
for (int i = l ; i <= r ; i++ ) {
if (val[dep][i] < sorted[mid]) val[dep + ][lpos++] = val[dep][i];
else if ( val[dep][i] == sorted[mid] && same > ) {
val[dep + ][lpos++] = val[dep][i];
same--;
} else val[dep + ][rpos++] = val[dep][i];
num[dep][i] = num[dep][l - ] + lpos - l;
}
build(l, mid, dep + );
build(mid + , r, dep + );
} int query(int L, int R, int l, int r, int dep, int k) {
if (l == r) {
if (val[dep][l] <= k) return ;
else return ;
}
int mid = (L + R) >> ;
int cnt = num[dep][r] - num[dep][l - ];
if (sorted[mid] <= k) {
int newr = r + num[dep][R] - num[dep][r];
int newl = newr - (r - l + - cnt) + ;
return cnt + query(mid + , R, newl, newr, dep + , k);
} else {
int newl = L + num[dep][l - ] - num[dep][L - ];
int newr = newl + cnt - ;
if (newr >= newl) return query(L, mid, newl, newr, dep + , k);
else return ;
}
}
int main() {
int t, n, m, l, r, k, cas = ;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
for (int i = ; i <= n ; i++ ) {
scanf("%d", &val[][i]);
sorted[i] = val[][i];
}
sort(sorted + , sorted + n + );
build(, n, );
printf("Case %d:\n", cas++);
while(m--) {
scanf("%d%d%d", &l, &r, &k);
printf("%d\n", query(, n, l + , r + , , k));
}
}
return ;
}

HDU 4417 划分树写法的更多相关文章

  1. HDU 4417 (划分树+区间小于k统计)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4417 题目大意:给定一个区间,以及一个k值,求该区间内小于等于k值的数的个数.注意区间是从0开始的 ...

  2. hdu 4417 划分树

    思路:二分枚举区间第k大.用划分树查找是否符合要求的高度. #include<iostream> #include<algorithm> #include<cstdio& ...

  3. HDU 4417 划分树+二分

    题意:有n个数.m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k. 划分树--查找区间第k大的数.... 利用划分树的性质.二分查找在区间[l,r]小于等于k的个数. 假设在区间第 i ...

  4. HDU 4417 主席树写法

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

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

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

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

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

  7. hdu 4251 划分树

    思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstdio> #include<cmath ...

  8. hdu 2665 划分树

    思路:裸的划分树 #include<iostream> #include<algorithm> #include<cstring> #include<cstd ...

  9. 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组

    题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...

随机推荐

  1. latex03-LaTeX中的中文处理办法

    编译含中文的tex文件的前提有三个: 默认编译器为XeLaTeX: 编辑器的默认字体编码格式为UTF-8: 引入ctex的宏包. 效果: 源码: %导言区 \documentclass{article ...

  2. C errno是否是线程安全的

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/138 在使用多线程时,遇到了一个问题:线程例程中如果需要使用er ...

  3. PHP.46-TP框架商城应用实例-后台21-权限管理-权限和角色的关系

    权限和角色的关系 权限功能 角色功能 权限与角色的关联要通过权限-角色表进行{多对多} /********* 角色-权限表 *********/ drop if exists p39_role_pri ...

  4. Coap协议学习笔记-第一篇

    1. 物联网应用上一般使用单片机(或者其他SOC),单片机的RAM内存一般只有20KB~~128KB左右,然而一个TCP协议栈可能就20KB,所以只能用UDP,因为UDP相对小很多,然后在UDP上加了 ...

  5. Linux使用imagemagick的convert命令压缩图片,节省服务器空间

    1,安装imagemagick yum install ImageMagick 2,获取图片 find ./ -regex '.*\(jpg\|JPG\|png\|jpeg\)' -size +500 ...

  6. MYSQL--事务处理(转)

    事务处理在各种管理系统中都有着广泛的应用,比如人员管理系统,很多同步数据库操作大都需要用到事务处理.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如 ...

  7. 安装Sql Server 2008的时候报错说找不到某个安装文件

           在安装Sql Server 2008的时候,报错说找不到某个安装文件,但是这个文件明明在那,百思不得其解.           最后看到一个老外的文章里面说,你要确认,你能访问到这个文件 ...

  8. VM打开虚拟机文件报错

    用VM打开以前的虚拟机文件报错 Cannot open the disk 'F:/****.vmdk' or one of the snapshot disks it depends on. 这种问题 ...

  9. Github上的1000多本免费电子书重磅来袭!

    Github上的1000多本免费电子书重磅来袭!   以前 StackOverFlow 也给出了一个免费电子书列表,现在在Github上可以看到时刻保持更新的列表了. 瞥一眼下面的书籍分类目录,你就能 ...

  10. 手把手教你玩转CSS3 3D技术

    手把手教你玩转 CSS3 3D 技术   要玩转css3的3d,就必须了解几个词汇,便是透视(perspective).旋转(rotate)和移动(translate).透视即是以现实的视角来看屏幕上 ...