HDU 4417 Super Mario 主席树
分析:找一个区间里小于等于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 主席树的更多相关文章
- 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)Total ...
- HDU 4417 Super Mario(划分树问题求不大于k的数有多少)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4417 - Super Mario ( 划分树+二分 / 树状数组+离线处理+离散化)
题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案. ...
- HDU 4417 Super Mario ( 离线树状数组 )
把数值和查询放在一起从小到大排序,纪录每个数值的位置,当遇到数值时就更新到树状数组中,遇到查询就直接查询该区间和. #include <cstdio> #include <cstri ...
- HDU 4417 Super Mario(划分树+二分)
题目链接 #include <cstdio> #include <cstring> #include <algorithm> using namespace std ...
- 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 ...
- hdu 4417 Super Mario (主席树)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ...
随机推荐
- yii2 用gii生成后台模块 view path描述
view path 格式: @backend/views/refund , 注意@和/
- ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order
如果在ECshop后台批量添加过大量类目的人都能体会到是多么的不方便(这点还是要说一下ECshop的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...
- (转载)delphi 中如何调用sql 存储过程
delphi 中如何调用sql 存储过程 使用TADOStoredProc组件,可以,给你举个例子好了 with ADOStoredProc1 do begin Close; Parameters.C ...
- 【Druid】 阿里巴巴推出的国产数据库连接池com.alibaba.druid.pool.DruidDataSource
阿里巴巴推出的国产数据库连接池,据网上测试对比,比目前的DBCP或C3P0数据库连接池性能更好 简单使用介绍 Druid与其他数据库连接池使用方法基本一样(与DBCP非常相似),将数据库的连接信息 ...
- 【@ContextConfiguration】java世界的那些注解
@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件 单个文件 @ContextConfiguration(Locations="../a ...
- Hadoop集群(第5期)_Hadoop安装配置
1.1 Hadoop简介 Hadoop是Apache软件基金会旗下的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS,Hadoop Distributed Filesystem)和Map ...
- [转载]C#读写配置文件(XML文件)
.xml文件格式如下 [xhtml] view plaincopy <?xml version="1.0" encoding="utf-8"?> & ...
- uva 12648
一个简单的搜索: 反正树的结构不会变,只需要把节点的名称换一下就行: 可惜比赛的时候思路不清晰: #include<cstdio> #define maxn 5050 #include&l ...
- PHP7正式版测试,性能惊艳!
本周迎来2015年编程语言界的两件大事,Swift7 开源, PHP7 发布.这两件大事,都是可以载入相应的编程语言的史册级的事件. Swift 开源的事,咱先不说了,知乎上也有热烈的讨论,我们今天就 ...
- nginx -t "nginx: [warn] only the last index in "index" directive should be absolute in 6 "的问题解决
修改完nginx的配置文件之后,执行nginx -t命令提示"nginx: [warn] only the last index in "index" directive ...