题目链接:传送门

题目大意:一个大小为 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)的更多相关文章

  1. hdu4417(Super Mario)—— 二分+划分树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. LPC(Low Pin Count) 与SIO(Super IO)

    记录bios学习的点点滴滴,虽然已经学了很长时间才发出来,但就当是温故而知新吧,由于水平有限,难免存在错误,望指正,同时感谢CSDN提供的平台. 1.LPC 定义:​ Intel所定义的PC接口,将以 ...

  3. 文件类似的推理 -- 超级本征值(super feature)

         基于内容的变长分块(CDC)技术,能够用来对文件进行变长分块.而后用来进行反复性检測,广泛用于去重系统中.后来又出现了对相似数据块进行delta压缩,进一步节省存储开销. 所以就须要一种高效 ...

  4. Gym - 101498G(Super Subarray )

    In this problem, subarray is defined as non-empty sequence of consecutive elements. We define a suba ...

  5. 数据库设计和ER模型-------之关系模型的基本概念(第二章)

    关系模型的基本术语 定义:用二维表格来表示实体集,用关键码表示实体之间联系的数据模型称为关系模型 有时也习惯称呼关系为表或表格,元组为行(Row),属性为列.关系中属性个数称为“元数”,元组个数称为“ ...

  6. 设计模式(十六)迭代器模式 Iterator

    什么时候需要用到迭代器模式? 有许多中方法,可以把对象堆起来放进一个集合(可以是数组.堆栈.列表.哈希表,等等). 每一种类型的集合,都有各自适用的时机.但是某个时间段,客户端可能希望去遍历这个集合. ...

  7. 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.单继 ...

  8. 清晰架构(Clean Architecture)的Go微服务: 依赖注入(Dependency Injection)

    在清晰架构(Clean Architecture)中,应用程序的每一层(用例,数据服务和域模型)仅依赖于其他层的接口而不是具体类型. 在运行时,程序容器¹负责创建具体类型并将它们注入到每个函数中,它使 ...

  9. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

随机推荐

  1. Linux下 sleep函数的注意事项

    1. 休眠sleep(unsigned int)为线程内操作  所以如果不同线程,信号量SIGALRM是不能中断sleep():  编写程序进行测试 //timercreate_demo.cpp #i ...

  2. 在Cocos2d-X中使用xml

    XML就可以扩展标记语言.在游戏开发中,经常使用于保存游戏信息,如最高分,游戏等级.等信息,和描写叙述一些资源等,我第一次使用xml是在使用CCAnimation创建动画中,使用plist文件载入动画 ...

  3. vue 发送ajax请求

    一. 简介 1.vue本身不支持发送AJAX请求,需要使用vue-resource(vue1.0版本).axios(vue2.0版本)等插件实现 2.axios是一个基于Promise的HTTP请求客 ...

  4. Vue2.0+Webpack项目环境构建到发布

    前言:为什么要用webpack搭建项目呢,因为这个工具可以把目前浏览器不全部支持的ES6语法,通过打包工具生成所有浏览器都支持的单个JS文件. 参考: https://blog.csdn.net/u0 ...

  5. unity, multi collider

    比如下面鸭子模型,只用一个box collider难以很好地吻合其的外形. 我们可以为它添加两个box collider,如下图所示: 注意: 1,colliders一定要添加在模型根节点(即图中do ...

  6. Informix 語法

    1.修改表名稱 RENAME TABLE old_table_name TO new_table_name; 2.分頁 select  SKIP 0 FIRST 1 * from tablename ...

  7. 蜜果私塾:informix数据库学习合集[不断补充]

    一.infomix使用备忘录     目录结构:     1. 启动与停止命令:      2. 修改数据库编码:      3. 查看informix占用的端口:      4. 使用dbacces ...

  8. docker 不同机器上容器互相通信

    环境说明: 1.系统:centos7 2.docker:Docker version 1.3.2 3.docker启动参数:OPTIONS=--selinux-enabled=false -H fd: ...

  9. linux中使用lftp上传下载文件

    lftp是linux中一款ftp服务器相比windows中的ftp显得要复杂不少了,下面我来总结一下lftp文件上传,文件下载,及文件查找等等相关命令吧. lftp连接的几种方法,最常用的是lftp ...

  10. aix 常用命令

    官网上的介绍: AIX 常用命令汇总 http://www.ibm.com/developerworks/cn/aix/library/au-dutta_cmds.html 我们先SSH 到AIX 系 ...