分析:找一个区间里小于等于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. jquery.animate用法

    <!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/1.10. ...

  2. 【jpa】 引用包的问题

    Hibernate使用Annotation(注解)需加                         hibernate-jpa-2.0-api-1.0.0.Final.jar Hibernate3 ...

  3. dtv_driver.ko

            替换dtv_driver.ko .步骤:         shell@android:/ # get_rootfs.sh                                 ...

  4. ubuntu中文版切换为英文后字体变化问题解决

    为了熟悉更多Linux 的英语词汇,希望把Ubuntu 的界面换成英文的.使用System->Administration->Language Suport( 系统-> 管理-> ...

  5. hdu 1043 pku poj 1077 Eight (BFS + 康拓展开)

    http://acm.hdu.edu.cn/showproblem.php?pid=1043 http://poj.org/problem?id=1077 Eight Time Limit: 1000 ...

  6. js正则匹配查找

    var pattern1 = /好/g; console.log(pattern1.test("你好")); 字符串查找: var pattern1 = /\w/; console ...

  7. 什么是 DevSecOps?系列(一)

    什么是 DevSecOps? 「DevSecOps」 的作用和意义建立在「每个人都对安全负责」的理念之上,其目标是在不影响安全需求的情况下快速的执行安全决策,将决策传递至拥有最高级别环境信息的人员. ...

  8. JAVA客户端API调用memcached两种方式

    1. memcached client for java客户端API:memcached client for java 引入jar包:java-memcached-2.6.2.jar package ...

  9. [Gauss]POJ3185 The Water Bowls

    题意:反正就是要给的一串01的变成全0 能影响自己和左右 最少需要几步 01方程组 异或解 ][]; // 增广矩阵 ]; // 解 ]; // 标记是否为自由未知量 int n; void debu ...

  10. ASP.NET MVC 入门介绍 (上)

    MVC模式 MVC模式是一种软件架构模式.它把软件系统分为三个部分:模型(Model),视图(View)和控制器(Controller).MVC模式最早由Trygve Reenskaug在1974年提 ...