题目链接:hdu_4417_Super Mario

题意:

给你n个树,有m个询问,每个询问有一个区间和一个k,问你这个区间内不大于k的数有多少个。

题解:

考虑用主席树的话就比较裸,当然也可以用其他的写

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++)
using namespace std; const int N=1e5+;
int a[N],t,n,m,hsh[N],hsh_len,root[N],tot,x,y,pos,ic=,k;
struct node{int l,r,sum;}T[N*]; inline int getid(int x){return lower_bound(hsh+,hsh++hsh_len,x)-hsh;}
inline int getd(int x){return upper_bound(hsh+,hsh++hsh_len,x)-hsh-;} void update(int &x,int y,int pos,int l=,int r=n)
{
T[++tot]=T[y],T[tot].sum++,x=tot;
if(l==r)return;
int m=(l+r)>>;
if(pos<=m)update(T[x].l,T[y].l,pos,l,m);
else update(T[x].r,T[y].r,pos,m+,r);
} int query(int x,int y,int pos,int l=,int r=n)
{
if(l==r)return T[y].sum-T[x].sum;
int m=(l+r)>>;
if(pos<=m)return query(T[x].l,T[y].l,pos,l,m);
else return T[T[y].l].sum-T[T[x].l].sum+query(T[x].r,T[y].r,pos,m+,r);
} int main()
{
scanf("%d",&t);
while(t--)
{
printf("Case %d:\n",ic++);
scanf("%d%d",&n,&m),tot=;
F(i,,n)scanf("%d",a+i),hsh[i]=a[i];
sort(hsh+,hsh++n),hsh_len=unique(hsh+,hsh++n)-hsh-;
F(i,,n)update(root[i],root[i-],getid(a[i]));
F(i,,m)scanf("%d%d%d",&x,&y,&pos),printf("%d\n",(k=getd(pos))==?:query(root[x],root[y+],k));
}
return ;
}

hdu_4417_Super Mario(主席树)的更多相关文章

  1. HDU 4417 Super Mario 主席树

    分析:找一个区间里小于等于h的数量,然后这个题先离散化一下,很简单 然后我写这个题主要是熟悉一下主席树,其实这个题完全可以离线做,很简单 但是学了主席树以后,我发现,在线做,一样简单,而且不需要思考 ...

  2. HDU4417 - Super Mario(主席树)

    题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...

  3. HDU-4417-Super Mario(主席树解法)

    Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...

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

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

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

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

  6. 主席树:HDU 4417 Super Mario

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

  7. Super Mario HDU - 4417 (主席树)

    Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...

  8. hdu 4417 Super Mario 树状数组||主席树

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

  9. Super Mario(主席树)

    Super Mario  Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded ...

随机推荐

  1. Tip of the Day

    Did you know ... ? You can view all statements within the method where certain exceptions can be cau ...

  2. button 自动刷新当前页面

    button请始终为按钮规定 type 属性.Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "sub ...

  3. java四种xml解析区别

    1.DOM解析 dom解析是根据树形结构解析,将整个文档加载到内存中,因此对内存的要求较高,所以可以对该文档数据进行多次操作(增,删,改,查). 2.SAX解析 SAX解析是根据事件模型解析,边读取文 ...

  4. 最近一段时间get到的小知识(c++的)

    (1)查看一个程序运行的时间 int main() { clock_t start,end; start=clock(); ... end=clock(); cout<<"Run ...

  5. MQTT协议之 Apache Apollo服务

    一.说明 MQTT是IBM开发的一个即时通讯协议,有可能成为物联网的重要组成部分.该协议支持所有平台,几乎可以把所有联网物品和外部连接起来,被用来当做传感器和致动器(比如通过Twitter让房屋联网) ...

  6. Unity3d请求webservice

    我们在对接第三方sdk时,第三方sdk通常会以一个webservice接口的形式供我们来调用.而这些接口会以提供我们get,post,soap等协议来进行访问.get,post方法相信大家都比较熟悉了 ...

  7. 详解 UIView 的 Tint Color 属性

    在iOS 7后,UIView新增加了一个tintColor属性,这个属性定义了一个非默认的着色颜色值,其值的设置会影响到以视图为根视图的整个视图层次结构.它主要是应用到诸如app图标.导航栏.按钮等一 ...

  8. 相机标定 matlab opencv ROS三种方法标定步骤(1)

    一 . 理解摄像机模型,网上有很多讲解的十分详细,在这里我只是记录我的整合出来的资料和我的部分理解 计算机视觉领域中常见的三个坐标系:图像坐标系,相机坐标系,世界坐标系,实际上就是要用矩阵来表 示各个 ...

  9. mozilla your firefox profile cannot be loaded. it may be missing or inaccessible

    check the permissions ls -l ~/.cache | grep mozilla fix the permissions sudo chown -R $USER:$USER ~/ ...

  10. mob.com Android studio 配置环境