【HDU 4417】Super Mario 【主席树】
来源:互联网 发布:python 宏定义 编辑:程序博客网 时间:2024/04/29 07:00
#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<cctype>using namespace std;char inc;inline void get(int& x){x = 0;inc =getchar();while(!isdigit(inc))inc=getchar();while(isdigit(inc)){x=x*10+inc-'0';inc=getchar();}}const int maxn = 100010;int T,casecnt,n,m;int a[maxn],hashrank[maxn],tot;int getrank(int x){return lower_bound(hashrank+1,hashrank+1+tot,x)-hashrank;}int x,y,h,root[maxn],cnt;struct Node{int ls,rs;int sum;}tr[maxn*40];void update(int& u,int v,int l,int r,int p){++cnt;tr[cnt]=tr[v];tr[cnt].sum++;u=cnt;if(l==r)return;int mid = (l+r)>>1;if(p<=mid)update(tr[u].ls,tr[v].ls,l,mid,p);else update(tr[u].rs,tr[v].rs,mid+1,r,p);}int query(int x,int y,int l,int r){if(l==r)return tr[y].sum-tr[x].sum;int mid = (l+r)>>1;if(h<=mid)return query(tr[x].ls,tr[y].ls,l,mid);else return query(tr[x].rs,tr[y].rs,mid+1,r)+tr[tr[y].ls].sum-tr[tr[x].ls].sum;}int main(){get(T);while(T--){cnt = 0;get(n);get(m);for(int i=1;i<=n;i++)get(a[i]),hashrank[i]=a[i];sort(hashrank+1,hashrank+1+n);tot = unique(hashrank+1,hashrank+1+n)-hashrank-1;for(int i=1;i<=n;i++)a[i]=getrank(a[i]);for(int i=1;i<=n;i++)update(root[i],root[i-1],1,tot,a[i]);printf("Case %d:\n",++casecnt);for(int i=1;i<=m;i++){get(x);get(y);get(h);x++,y++;h = upper_bound(hashrank+1,hashrank+1+tot,h)-hashrank-1;if(h==0)puts("0");else printf("%d\n",query(root[x-1],root[y],1,tot));}}return 0;}
1 0
- hdu 4417 Super Mario (主席树+二分)
- 【HDU 4417】Super Mario 【主席树】
- HDU 4417 Super Mario(主席树)
- HDU 4417-Super Mario(主席树)
- hdu 4417 Super Mario(主席树)
- HDU-4417 Super Mario (主席树)
- HDU 4417 Super Mario(线段树离线处理/主席树)
- hdu-4417-Super Mario-只查询的主席树
- [hdu 4417 Super Mario] 主席树+离散化 OR 分块
- hdu 4417 Super Mario(主席树||cdq分治+树状数组)
- [Hdu] 4417 Super Mario (主席树模板题)
- Hdu 4417 Super Mario(主席树+二分)
- HDU 4417 Super Mario [可持久化线段树 主席树]
- 【主席树】 HDU 4417 Super Mario 区间内小于某值的个数
- hdu-4417-Super Mario(无修改的主席树-求小于等于k的个数)
- HDU 4417 Super Mario(树状数组离线处理 or 主席树)
- HDU 4417 Super Mario (主席树,区间小于k的个数)
- hdu-4417-Super Mario
- Easyui treegrid idField字段引起的错误:maximum call stack size exceeded
- db2 下载
- 跟着Innost理解下ContentProvider
- 解决bootstrapTable refresh模态框scrollbar消失,焦点在parent窗口上的问题
- Excel 有条件的情况下,统计多列的总和(对比SUMIF和SUMPRODUCT)(亲自实践)
- 【HDU 4417】Super Mario 【主席树】
- 基于Linux/Openwrt平台的H3C客户端
- C# 格式化输出
- doubango编译总结
- Java的传值与传引用
- android 键盘显示/隐藏
- 年月日时间和64位时间的使用及相互转换
- spring事务控制--xml配置与annotation注解 优先级对比
- pads如何实现点击原理图就能在pcb与之对应的元器件变色