hdu_4417_Super Mario(主席树)
题目链接: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(主席树)的更多相关文章
- HDU 4417 Super Mario 主席树
分析:找一个区间里小于等于h的数量,然后这个题先离散化一下,很简单 然后我写这个题主要是熟悉一下主席树,其实这个题完全可以离线做,很简单 但是学了主席树以后,我发现,在线做,一样简单,而且不需要思考 ...
- HDU4417 - Super Mario(主席树)
题目大意 给定一个数列,每次要求你查询区间[L,R]内不超过K的数的数量 题解 和静态的区间第K大差不多,这题是<=K,先建立好n颗主席树,然后用第R颗主席树区间[1,K]内数的数量减去第L-1 ...
- HDU-4417-Super Mario(主席树解法)
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...
- HDU 4417 Super Mario 主席树查询区间小于某个值的个数
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> ...
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 主席树:HDU 4417 Super Mario
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Super Mario HDU - 4417 (主席树)
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...
- hdu 4417 Super Mario 树状数组||主席树
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- Super Mario(主席树)
Super Mario Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded ...
随机推荐
- 借助OpenOffice实现office转pdf(Java)的.exe小程序
原料:OpenOffice4.1.2(之所以选OpenOffice是因为可以跨平台,下载后直接安装),jodconverter-core-3.0-beta-4-dist.zip(可以搜博客园),Exe ...
- ffmpeg的安装--opencv视频处理必备
安装yasm(ffmpeg必备)wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gztar xzvf yasm-1. ...
- Mysql之Windows初探
准备工作 防止原先mysql残留,DOS模式下删除mysql服务 sc delete mysql 或者 进入mysql目录下子目录bin卸载mysql服务 mysqld --remove mysql ...
- [转载]We Recommend a Singular Value Decomposition
原文:http://www.ams.org/samplings/feature-column/fcarc-svd Introduction The topic of this article, the ...
- python3 数据类型
Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) Number(数字) Py ...
- 删除 CentOS7 更新后产生的多余的内核
今天更新完系统的内核,重启电脑时发现突然多了一个启动项,想删除多余的启动项,在上网查找后,找到了下面的方法,经过测试,是完全可行的.自己写下来,以便以后用到.1.# uname -a 列出系统中正在使 ...
- EasyCHM(CHM电子书制作工具) v3.84.545 绿色版
软件名称:EasyCHM(CHM电子书制作工具) v3.84.545 绿色版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 2.78MB 图片预览: 软件 ...
- java基础第二天
学习了关键字,标识符,数据类型.变量和常量,运算符和表达式,开始编写一些简单的输入输出运算的程序了.
- 安装oracle 10g时提示:操作系统版本: 必须是5.1或者5.2 怎么办?
1.在安装目录中搜索refhost.xml,然后在适当位置添加以下内容,注意括号配对 <!--Microsoft Windows 7--> <OPERATING_SYSTEM> ...
- 敏捷开发(六)- SCRUM全员会议
本文主要是为了检测你对SCRUM 全员会议的了解和使用程度,通过本文你可以检测一下 1.你们的SCRUM 全员会议的过程和步骤 2.SCRUM 全员会议的输出结果 一.会议目的 组成团 ...