分析:找一个区间里小于等于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. 控制 WAP 网站上输入框的默认类型

    比如手机号,卡输入框应该默认显示数字键盘,邮箱输入框应该默认显示邮箱键盘.www . c s d n 1 2 3 . com/html/itweb/20130802/36036_36043_36004 ...

  2. JS判断上传图片格式是否正确

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. 配置 Struts2 Hello World

    http://javaweb.group.iteye.com/group/wiki/1505-struts2-under-helloworld---how-to-make-the-first-of-t ...

  4. php验证身份证号码正确性

    发布:JB01   来源:脚本学堂     [大 中 小] 分享一例php代码,用于验证身份证号码的正确性,用到了preg_match.preg_replace函数,有需要的朋友可以参考学习下.本文转 ...

  5. Yii通过控制台命令创建定时任务

    假设Yii项目路径为 /home/apps/ 1. 创建文件 /home/apps/protected/commands/crons.php <?php $yii = '/home/apps/f ...

  6. Fluid Shopping Website 开发阶段性总结——第一周

    开发目的: 可链接微信公众号,无论是桌面端.移动端完美兼容,给用户提供不逊于原生App的用户体验.作为一个软件,有充分的可扩展性,便于未来增强开发.同时给一些正在尝试做OTO的朋友们提供一个平台,因为 ...

  7. 一步步学习NHibernate(1)——NHibernate介绍

    请注明转载地址:http://www.cnblogs.com/arhat 第十五章 从本章开始,老魏将给大家一起学习NHibernate这个流行的ORM框架,本来老魏想要和大家一起探讨微软的EF框架的 ...

  8. js数值计算

    js在小数数值计算时会出现误差,比如0.19+15.02=15.20999999999999,出现此问题的原因,百度上有,为了避免误差产生可以这样做:(0.19*100+15.02*100)/100.

  9. c++重载与覆写

    重载:指子类改写了父类的方法,覆写:指同一个函数,同样的参数列表,同样的返回值的,但是函数内部的实现过程不同. 重载: 1.方法名必须相同. 2.参数列表必须不相同,与参数列表的顺序无关. 3.返回值 ...

  10. 【弱省胡策】Round #6 String 解题报告

    感觉这个题好神啊. 首先我们只管 $a = b$ 的情况,那么我们自然就可以把这个串对 $a$ 取模,然后用 KMP 求出能弄出几个其他的 B 串. 具体就是把串先倍长,然后倒过来,然后求 $Next ...