题目链接: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. httpclient用法

    Http通信方式:HttpURLConnection和HttpClient HttpURLConnection是java的标准类,什么都没封装,用起来太原始,不方便HttpClient就是一个增强版的 ...

  2. js 增加 onclick 事件

    obj.onclick = function(){check(this)} function check(obj){ alert(obj)l }

  3. Linux学习初步

    centOS 6.5关闭防火墙步骤  关闭命令:  service iptables stop         永久关闭防火墙:chkconfig iptables off两个命令同时运行,运行完成后 ...

  4. iOS-延迟操作方法总结

    在实际应用中,有时候我们会需要延时执行某些操作,所以我们这里总结了四种延迟操作的方法,并简要分析了每种方法的异同. NSObject的相关方法 第一种方法是使用NSObject类的performSel ...

  5. CodeForces 670A Holidays

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  6. HDU 5889 Barricade

    最短路,最小割,网络流. 可以根据$dis[u]+1$与$dis[v]$的大小关系判断$<u,v>$是否为最短路上的边,可以处理出一个只包含最短路的$DAG$,然后求这个$DAG$的最小割 ...

  7. HDU 5873 Football Games

    随便判了几个条件就过了,也不知道对不对的. 正解应该是: $[1].$${s_1} + {s_2} + {s_3} + ...... + {s_n} = n(n - 1)$ $[2].$${s_1} ...

  8. C#中的委托到底是什么概念??

    委托,简单理解是这样的.比如您要管您的孩子,把孩子送进了幼儿园.OK.此时您就把您的孩子委托给了幼儿园.当幼儿园放学,将孩子交还给您的手中.则是委托的回调.当然我这里的例子是说异步委托调用.您也可以同 ...

  9. 【锋利的Jquery】读书笔记二

    一.jquery选择器 基本选择器 层次选择器 过滤选择器 基本过滤 内容过滤 可见性过滤 属性过滤 子元素过滤 first  : 获取单个元素       $("div:first&quo ...

  10. dplyr 数据操作 常用函数(2)

    继上一节常用函数,继续了解其他函数 1.desc() 这个函数和SQL中的排序用法是一样的,表示对数据进行倒序排序. 接下来我们看些例子. a=sample(20,50,rep=T)a desc(a) ...