题目链接:传送门

题目大意:一个大小为 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. centos7删除原docker 安装新docker-ce

    这里用阿里云的镜像源,速度会快很多: yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager -- ...

  2. Guid.NewGuid().ToString()得几种格式显示

    1.Guid.NewGuid().ToString("N") 结果为:        38bddf48f43c48588e0d78761eaa1ce6 2.Guid.NewGuid ...

  3. linux下重新定位SVN URL方法

    linux下重新定位SVN URL方法:   如果更换了SVN服务器,就需要重新定位,指向新的SVN URL. 重新定位命令:svn switch --relocate 原svn地址 新svn地址   ...

  4. Redis(八):spring data redis 理解

    前言 Spring Data Redis project,应用了Spring概念来开发使用键值形式的数据存储的解决方案.我们(官方)提供了一个 "template" ,这是一个高级 ...

  5. springmvc mybatis 声明式事务管理回滚失效,(checked回滚)捕捉异常,传输错误信息

    一.知识点及问题 后端框架: Spring .Spring mvc .mybatis 业务需求: client先从服务端获取用户大量信息到client,编辑完毕之后统一Post至服务端,对于数据的改动 ...

  6. p4n 今天与朋友沟通支付云服务普及以及跨境电子商务的光辉前景

    p4n 今天与朋友沟通支付云服务普及以及跨境电子商务的光辉前景 跨境电子商务也是个光忙四色和的跨境电子商务啊..支付项目也是个强大的项目.. 过几天我们就要宣布正式发布atipay ,并宣称将致力于推 ...

  7. atitit.自己动手开发编译器and解释器(2) ------语法分析,语义分析,代码生成--attilax总结

    atitit.自己动手开发编译器and解释器(2) ------语法分析,语义分析,代码生成--attilax总结 1. 建立AST 抽象语法树 Abstract Syntax Tree,AST) 1 ...

  8. location if (.....) #if与中括号之间要有空格

    [root@web01 default]# /app/server/nginx/sbin/nginx -t nginx: [emerg] unknown directive nginx: config ...

  9. iOS开发之使用AFN上传图片

    //1.创建管理者对象 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializ ...

  10. libcpmt.lib (xxx.obj) LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in XXX.obj

    问题描述: 这样的,我写了个NString类,然后用的VS2013的命令行编译的(NMAKE.exe),并用LNK.exe打包成了NString.lib 然后后来我在VS2013里面建了一个proje ...