题目链接:传送门

题目大意:一个大小为 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. hdu5293 Tree chain problem 树形dp+线段树

    题目:pid=5293">http://acm.hdu.edu.cn/showproblem.php?pid=5293 在一棵树中,给出若干条链和链的权值.求选取不相交的链使得权值和最 ...

  2. unity5, 在mac下多开

    mac上app的多开与app本身无关,而是系统本身的功能,使用命令 open -n 就可以实现打开某应用程序的一个新实例(自行输入man open查看含义). 参考:http://mac-how-to ...

  3. Mybatis(一):MyBatis配置文件config.xml详解

    MyBatis 配置文件基本结构 在使用mybatis框架时,首先导入其对应的jar包,并进行相应的配置,所以得对配置文件的每个参数都得了解.一个完全的mybatis配置文件结构如下: <?xm ...

  4. location 禁止多目录

    [root@web01 default]# mkdir cron templates [root@web01 default]# tree . ├── cron └── templates direc ...

  5. struts2拦截器的实现原理及源码剖析

    拦截器(interceptor)是Struts2最强大的特性之一,也可以说是struts2的核心,拦截器可以让你在Action和result被执行之前或之后进行一些处理.同时,拦截器也可以让你将通用的 ...

  6. web压力测试指标

    1.TPS每秒钟完成的web请求响应数量TPS=并发数/响应时间TPS是衡量系统性能的重要指标 2.并发数时间段内,系统同时处理的web请求响应数量 3.响应时间所有web请求处理完毕的时间 4.吞吐 ...

  7. [Spring Framework]学习笔记--@Component等stereotype的基础

    在继续讲解Spring MVC之前,需要说一下常用的几个用来标记stereotype的annotation. @Component,@Controller,@Repository,@Service. ...

  8. C++重载IO操作符

    操作符的重载有一定的规则,而IO操作符必须重载为普通函数,且应该声明为类的友元函数.我试了,非友元也可以,但是必须提供访问成员变量的函数,所以,出于效率的考虑还是应该定义为友元. 规则如下: 1.  ...

  9. spring boot热部署pom.xml配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  10. js json对象和数组对象

    动态添加json对象: var json = {}; json['a'] = 'a'; 动态添加数组对象: var arr = []; arr['a'] = 'a';