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 ...
随机推荐
- 7个jquery easy ui 基本组件图解
以下给出7个jquery easy ui 基本组件: 1 基本面板 <!DOCTYPE html> <html> <head> <meta charset=& ...
- REST开放接口生成文档工具之apidoc
一.安装node.js环境 感谢阿里云,下载的链接http://npm.taobao.org/mirrors/node/latest-v6.x/ 二.安装apidoc npm install apid ...
- 04-树7. Search in a Binary Search Tree (25)
04-树7. Search in a Binary Search Tree (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 ...
- sysbench的安装详解
sysbench是一个压力测试工具.可以用它来测试cpu.mem.disk.thread.mysql.postgr.oracle:然而作为一个mysql dba 我当然是用它来压测mysql啦! 一. ...
- 常用音频软件:Cool edit pro
作者:桂. 时间:2017-06-02 11:51:08 链接:http://www.cnblogs.com/xingshansi/p/6932671.html 这里只涉及Cool edit pro ...
- 常用音频软件:Wavesufer
作者:桂. 时间:2017-06-02 10:23:39 链接:http://www.cnblogs.com/xingshansi/p/6932408.html 前言 只列举两个自己用过的(wave ...
- s2sh框架整合具体配置-xml方式
s2sh整合之xml方式 说明:本文档所採用的框架版本号为:Struts 2.1.8, Sping2.5.5, Hibernate 3.5.6 1. 须要的jar包: ------------ ...
- 167. Add Two Numbers【easy】
You have two numbers represented by a linked list, where each node contains a single digit. The digi ...
- C# fixed详解
相信很多人在这样或那样的项目中,或者无意间看到了fixed语句块,看到之后你肯定会疑问: 1.这个fixed关键字是做什么用的? 2.什么情况下需要该关键字? 3.这个关键字该怎么用? 我相信解决了上 ...
- FreeRtos——空闲任务与空闲任务钩子函数
以下基础知识转载自正点原子PDF资料. 前面例子 中创建的任务大部份时间都处于阻塞态.这种状态下所有的任务都不可运行,所以也不能被调度器选中.但处理器总是需要代码来执行——所以至少要有一个任务处于运行 ...