分析:找一个区间里小于等于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. leetcode problem 33 -- Search in Rotated Sorted Array

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  2. 使用WebClient上传文件并同时Post表单数据字段到服务端

    之前遇到一个问题,就是使用WebClient上传文件的同时,还要Post表单数据字段,一开始以为WebClient可以直接做到,结果发现如果先 Post表单字段,就只能获取到字段及其值,如果先上传文件 ...

  3. 【InstallShield】 为什么卸载后有的文件没有删掉

    1.Component的属性Permanent设置为Yes. 2.Component的ID为空. 3.Component被其他应用程序或者Feature使用. 4.设置了一个Condition,在安装 ...

  4. python 调用第三方库压缩png或者转换成webp

    因为工作需要去研究了下png的压缩,发现转换成webp可以小很多,但是webp在手机上的解码速度比png的解码速度慢很多.出于进几年手机设备的处理器的性能也不错了,所以准备两套方案. 在网上搜索了一些 ...

  5. hdu 2087 剪花布条 KMP多次匹配

    剪花布条 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?   I ...

  6. 移动端Reactive Native轮播组件

    移动端Reactive Native轮播组件 总结下这段时间学习reactive native的一些东西,我们来认识一下,被炒得这么火的rn,究竟是个什么东西,以及如何去搭建自己的demo. reac ...

  7. 视图--bai

    /*视图的必要性 create view population_all_view as select xxxx 详细信息 from qgck where rownum<500 -- sql语句不 ...

  8. <六> jQuery 获得内容和属性

    获得内容 三个简单实用的用于 DOM 操作的 jQuery 方法: text() - 设置或返回所选元素的文本内容 html() - 设置或返回所选元素的内容(包括 HTML 标记) val() - ...

  9. hdu 2665 Kth number(划分树模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=2665 [ poj 2104 2761 ]  改变一下输入就可以过 http://poj.org/problem? ...

  10. Automotive Security的一些资料和心得(6):AUTOSAR

    1.1 Introduction AUTOSAR(汽车开放系统架构)是一个开放的,标准化的汽车软件架构,由汽车制造商,供应商和开发工具共同开发.它联合了汽车OEM ,供应商和开发工具供应商,其目标是创 ...