分析:找一个区间里小于等于h的数量,然后这个题先离散化一下,很简单

然后我写这个题主要是熟悉一下主席树,其实这个题完全可以离线做,很简单

但是学了主席树以后,我发现,在线做,一样简单,而且不需要思考

(主席树大法好)无限仰慕

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1e5+;
const int INF=0x3f3f3f3f;
typedef unsigned long long ULL;
typedef long long LL;
int n,m,a[N],c[N],T;
int root[N],sz;
struct Node{
int l,r,v;
}o[N*];
void update(int &rt,int l,int r,int pos){
o[++sz]=o[rt],rt=sz;
++o[rt].v;
if(l==r)return;
int mid=(l+r)>>;
if(pos<=mid)update(o[rt].l,l,mid,pos);
else update(o[rt].r,mid+,r,pos);
}
int query(int rt1,int rt2,int l,int r,int x,int y){
if(x<=l&&r<=y)
return o[rt2].v-o[rt1].v;
int mid=(l+r)>>;
int ans=;
if(x<=mid)ans+=query(o[rt1].l,o[rt2].l,l,mid,x,y);
if(y>mid)ans+=query(o[rt1].r,o[rt2].r,mid+,r,x,y);
return ans;
}
int main(){
int cas=;
scanf("%d",&T);
while(T--){
printf("Case %d:\n",++cas);
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%d",&a[i]),c[i]=a[i];
sort(a+,a++n);
int cnt=unique(a+,a++n)-a-;
root[]=sz=;
for(int i=;i<=n;++i){
c[i]=lower_bound(a+,a++cnt,c[i])-a;
update(root[i]=root[i-],,cnt,c[i]);
}
for(int i=;i<=m;++i){
int l,r,h;
scanf("%d%d%d",&l,&r,&h),++l,++r;
h=upper_bound(a+,a++cnt,h)-a;
if(h==){
printf("0\n");
continue;
}
printf("%d\n",query(root[l-],root[r],,cnt,,h-));
}
}
return ;
}

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

  1. HDU 4417 Super Mario 主席树查询区间小于某个值的个数

    #include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> ...

  2. HDU 4417 Super Mario(划分树)

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

  3. HDU 4417 Super Mario(划分树问题求不大于k的数有多少)

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

  4. HDU 4417 - Super Mario ( 划分树+二分 / 树状数组+离线处理+离散化)

    题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案. ...

  5. HDU 4417 Super Mario ( 离线树状数组 )

    把数值和查询放在一起从小到大排序,纪录每个数值的位置,当遇到数值时就更新到树状数组中,遇到查询就直接查询该区间和. #include <cstdio> #include <cstri ...

  6. HDU 4417 Super Mario(划分树+二分)

    题目链接 #include <cstdio> #include <cstring> #include <algorithm> using namespace std ...

  7. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

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

  8. 主席树:HDU 4417 Super Mario

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

  9. hdu 4417 Super Mario (主席树)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ...

随机推荐

  1. C/C++代码检视要点

    4.1.1       C/C++代码检视要点 代码检视技能属于开发人员的基本功,能够很大程度地反应出开发人员的能力水平,前面4.4.1节已经讲过提高评审检视的方法.下面以实际的C/C++语言方面的代 ...

  2. npm:Node.js的软件包管理器

    npm https://www.npmjs.com/ 2016-08-03

  3. 对WebClient扩展自动解压缩页面

    WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...

  4. Date、String、Calendar类型之间的转化

    原文出处:http://fjfj910.iteye.com/blog/1202219 1.Calendar 转化 String  //获取当前时间的具体情况,如年,月,日,week,date,分,秒等 ...

  5. Linux procfs详解

    1.0 proc文件系统总览在类Unix系统中体现了一种良好的抽象哲学,就是几乎所有的数据实体都被抽象成一个统一的接口--文件来看待,这样我们就可以用一些简单的基本工具完成大量复杂的操作.在Linux ...

  6. PHP 向 MySql 中数据修改操作时,只对数字操作有效,非数字操作无效,怎么办?

    问题描述:   用PHP向MySql数据库中修改数据,实现增删改(数据库能正确连接) 经测试,代码只能对数字进行正常的增删改操作,非数字操作无效   但要在课程名称中输入中文,应该如果修改呢?   存 ...

  7. find grep

    grep grep -rn "hello,world!" * #递归查找当前目录下所有包含hello,world的文件 grep -C number pattern files : ...

  8. Python基于比较的排序

    排序是算法学习中最基本的问题. 1.平均时间复杂度均为O(N2)的排序 1.1 插入排序 插入排序对少量元素的排序非常有效.工作机制就像打牌一样,为了将牌插入到已排好序的牌中,需要将牌与手中的牌从右向 ...

  9. IOS中如何判断APP是否安装后首次运行或升级后首次运行

    对于是否为首次安装的App可以使用如下方法来判断 [[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"] ...

  10. noj [1475] Bachelor (找1的个数)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1475 [1475] Bachelor 时间限制: 1000 ms 内存限制: 65535 K 问题描述 炎热的 ...