HDU4417 (Super Mario)
题目链接:传送门
题目大意:一个大小为 n 的数组,m组询问,每组询问[x,y]内<=v的数的数量。
题目思路:主席树(注意询问时数组下标越界问题)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 30010
typedef pair<int,int> PII;
typedef long long LL;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m,flag,L,R,sz;
struct Seg{int l,r,v;}seg[N*];
int a[N],b[N],root[N];
void init(){
root[]=sz=;
mst(seg,);
}
void update(int &rot,int rt,int l,int r){
seg[++sz]=seg[rot],rot=sz;
++seg[rot].v;
if(l==r)return;
int mid=l+r>>;
if(L<=mid)update(seg[rot].l,lson);
else update(seg[rot].r,rson);
}
int query(int L,int R,int rt,int l,int r,int v){
if(l==r)return seg[R].v-seg[L].v;
int mid=l+r>>,temp=;
if(v<=mid)temp+=query(seg[L].l,seg[R].l,lson,v);
else{
temp+=seg[seg[R].l].v-seg[seg[L].l].v;
temp+=query(seg[L].r,seg[R].r,rson,v);
}
return temp;
}
int main(){
int i,j,group,x,y,v,Case=;
group=read();
while(group--){
init();
n=read(),m=read();
for(i=;i<=n;++i)a[i]=read(),b[i]=a[i];
sort(b+,b+n+);int _n=unique(b+,b+n+)-b-;
for(i=;i<=n;++i){
L=lower_bound(b+,b+_n+,a[i])-b;
update(root[i]=root[i-],,,_n);
}
printf("Case %d:\n",++Case);
while(m--){
x=read(),y=read(),v=read();
++x,++y;
L=root[x-],R=root[y];
v=upper_bound(b+,b+_n+,v)-b-;
if(v) printf("%d\n",query(L,R,,,_n,v));
else printf("0\n");
}
}
return ;
}
HDU4417 (Super Mario)的更多相关文章
- hdu4417(Super Mario)—— 二分+划分树
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- LPC(Low Pin Count) 与SIO(Super IO)
记录bios学习的点点滴滴,虽然已经学了很长时间才发出来,但就当是温故而知新吧,由于水平有限,难免存在错误,望指正,同时感谢CSDN提供的平台. 1.LPC 定义: Intel所定义的PC接口,将以 ...
- 文件类似的推理 -- 超级本征值(super feature)
基于内容的变长分块(CDC)技术,能够用来对文件进行变长分块.而后用来进行反复性检測,广泛用于去重系统中.后来又出现了对相似数据块进行delta压缩,进一步节省存储开销. 所以就须要一种高效 ...
- Gym - 101498G(Super Subarray )
In this problem, subarray is defined as non-empty sequence of consecutive elements. We define a suba ...
- 数据库设计和ER模型-------之关系模型的基本概念(第二章)
关系模型的基本术语 定义:用二维表格来表示实体集,用关键码表示实体之间联系的数据模型称为关系模型 有时也习惯称呼关系为表或表格,元组为行(Row),属性为列.关系中属性个数称为“元数”,元组个数称为“ ...
- 设计模式(十六)迭代器模式 Iterator
什么时候需要用到迭代器模式? 有许多中方法,可以把对象堆起来放进一个集合(可以是数组.堆栈.列表.哈希表,等等). 每一种类型的集合,都有各自适用的时机.但是某个时间段,客户端可能希望去遍历这个集合. ...
- Python3 与 C# 面向对象之~继承与多态 Python3 与 C# 面向对象之~封装 Python3 与 NetCore 基础语法对比(Function专栏) [C#]C#时间日期操作 [C#]C#中字符串的操作 [ASP.NET]NTKO插件使用常见问题 我对C#的认知。
Python3 与 C# 面向对象之-继承与多态 文章汇总:https://www.cnblogs.com/dotnetcrazy/p/9160514.html 目录: 2.继承 ¶ 2.1.单继 ...
- 清晰架构(Clean Architecture)的Go微服务: 依赖注入(Dependency Injection)
在清晰架构(Clean Architecture)中,应用程序的每一层(用例,数据服务和域模型)仅依赖于其他层的接口而不是具体类型. 在运行时,程序容器¹负责创建具体类型并将它们注入到每个函数中,它使 ...
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- nyoj 37 回文字符串 【DP】
先反向复制一个新的字符串,然后再找出最长公共子串,在用长度n减去就可以 回文字符串 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 所谓回文字符串,就是一个字符串,从 ...
- cocos2d-html5学习笔记(六)--alpha2中cc.Sequence.create中的bug
cocos2d-html5学习笔记(六)--alpha2中cc.Sequence.create中的bug http://blog.csdn.net/allenice1/article/details/ ...
- [Informix] unload load
select tabname from systables where tabname like 'aa%' select * from syscolumns where tabname like ...
- Cookie/Session编码
Unicode编码:保存中文 中文与英文字符不同,中文属于Unicode字符,在内存中占4个字符,而英文属于ASCII字符,内存中只占2个字节.Cookie中使用Unicode字符时需要对Unicod ...
- MySQL存储过程使用实例详解
本文介绍关于在MySQL存储过程游标使用实例,包括简单游标使用与游标循环跳出等方法 例1.一个简单存储过程游标实例 DROP PROCEDURE IF EXISTS getUserInfo $$CRE ...
- atitit.D&D drag&drop拖拽文件到界面功能 html5 web 跟个java swing c#.net c++ 的总结
atitit.D&D drag&drop拖拽文件到界面功能 html5 web 跟个java swing c#.net c++ 的总结 1. DND的操作流程 1 2. Html5 注 ...
- Linux服务器丢包故障的解决思路及引申的TCP/IP协议栈理论
我们使用Linux作为服务器操作系统时,为了达到高并发处理能力,充分利用机器性能,经常会进行一些内核参数的调整优化,但不合理的调整常常也会引起意想不到的其他问题,本文就一次Linux服务器丢包故障的处 ...
- angularjs 构建主页 内置过滤器、日期的格式化
从构建负责管理主屏幕的 MainController 开始.在这个 MainController 控制器内,只需设置一个每秒运转一次,同时更新一个局部作用域变量的延时 angular.module(' ...
- 回文串dp
一个字符串如果从左往右读和从右往左读都一样,那么这个字符串是一个回文串.例如:"abcba","abccba". 蒜头君想通过添加字符把一个非回文字符串变成回文 ...
- kernel 4.4.12 移植 HUAWEI MU609 Mini PCIe Module
首先请参考 http://www.cnblogs.com/chenfulin5/p/6951290.html 上一章刚讲了 kernel 3.2.0 移植 MU609 这一章记录新版kernel 的移 ...