主席树+离散化。给一段区间。多次询问[l,r]中有多少个数小于k。啊主席树用指针版写出来优美多了QAQ。。。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
int read(){
int x=0;char c=getchar();bool f=true;
while(!isdigit(c)){
if(c=='-') f=false;c=getchar();
}
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return f?x:-x;
}
const int nmax=100005;
const int inf=0x7f7f7f7f;
struct node{
node *l,*r;int sum;
};
node *root[nmax],nodes[nmax*20],*pt;
int a[nmax],b[nmax];
node* build(int l,int r){
node* op=pt++;op->sum=0;
if(l==r) return op;
int mid=(l+r)>>1;
op->l=build(l,mid);op->r=build(mid+1,r);
return op;
}
node* update(int p,int add,node* t,int l,int r){
node* op=pt++;op->sum=t->sum+add;
if(l==r) return op;
int mid=(l+r)>>1;
if(p<=mid) op->r=t->r,op->l=update(p,add,t->l,l,mid);
else op->l=t->l,op->r=update(p,add,t->r,mid+1,r);
return op;
}
int query(node* t,node* s,int x,int l,int r){
if(l==r) return t->sum-s->sum;
int mid=(l+r)>>1;
if(x<=mid) return query(t->l,s->l,x,l,mid);
else return query(t->r,s->r,x,mid+1,r)+t->l->sum-s->l->sum;
}
int main(){
int cas=read();
REP(i,1,cas){
pt=nodes;
int n=read(),m=read();
REP(j,1,n) a[j]=b[j]=read();
sort(b+1,b+n+1);
int N=unique(b+1,b+n+1)-b-1;
N++;b[N]=inf; root[0]=build(1,N);
REP(j,1,n){
int k=lower_bound(b+1,b+N+1,a[j])-b;
root[j]=update(k,1,root[j-1],1,N);
} printf("Case %d:\n",i);
REP(j,1,m){
int l=read(),r=read(),v=read();l++,r++;
int k=upper_bound(b+1,b+1+N,v)-b-1;
int ans=0;
if(k>0) ans=query(root[r],root[l-1],k,1,N);
printf("%d\n",ans);
}
}
return 0;
}

  

Super Mario

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4662 Accepted Submission(s):
2148

Problem Description
Mario is world-famous plumber. His “burly” figure and
amazing jumping ability reminded in our memory. Now the poor princess is in
trouble again and Mario needs to save his lover. We regard the road to the
boss’s castle as a line (the length is n), on every integer point i there is a
brick on height hi. Now the question is how many bricks in [L, R] Mario can hit
if the maximal height he can jump is H.
 
Input
The first line follows an integer T, the number of test
data.
For each test data:
The first line contains two integers n, m (1
<= n <=10^5, 1 <= m <= 10^5), n is the length of the road, m is the
number of queries.
Next line contains n integers, the height of each brick,
the range is [0, 1000000000].
Next m lines, each line contains three integers
L, R,H.( 0 <= L <= R < n 0 <= H <= 1000000000.)
 
Output
For each case, output "Case X: " (X is the case number
starting from 1) followed by m lines, each line contains an integer. The ith
integer is the number of bricks Mario can hit for the ith query.
 
Sample Input
1
10 10
0 5 2 7 5 4 3 8 7 7
2 8 6
3 5 0
1 3 1
1 9 4
0 1 0
3 5 5
5 5 1
4 6 3
1 5 7
5 7 3
 
Sample Output
Case 1:
4
0
0
3
1
2
0
1
5
1
 
Source

hdu4177:Super Mario的更多相关文章

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

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

  2. Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learning Project

    Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learn ...

  3. 主席树:HDU 4417 Super Mario

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

  4. hdu4417 Super Mario 树阵离线/划分树

    http://acm.hdu.edu.cn/showproblem.php?pid=4417 Super Mario Time Limit: 2000/1000 MS (Java/Others)    ...

  5. Super Mario

    Super Mario Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

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

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

  7. hdu 4417 Super Mario 树状数组||主席树

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

  8. HDU 4417 Super Mario(线段树)

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

  9. HDU 4417 Super Mario(划分树)

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

随机推荐

  1. Python数据结构————二叉查找树的实现

    对于二叉查找树的每个节点Node,它的左子树中所有的关键字都小于Node的关键字,而右子树中的所有关键字都大于Node的关键字. 二叉查找树的平均深度是O(log N). 1.初始化 class Bi ...

  2. Microsoft Visual Studio Ultimate 2013 旗舰版 有效注册密钥

    Visual Studio Ultimate 2013 KEY(密钥):BWG7X-J98B3-W34RT-33B3R-JVYW9 Visual Studio Premium 2013 KEY(密钥) ...

  3. JS和JSP的区别

    最近很多同学在纠结于名词缩写之间的相似性,因此本人也来写一篇,讲讲JS和JSP的区别. SUN首先发展出SERVLET,其功能比较强劲,体系设计也很先进,只是,它输出HTML语句还是采用了老的CGI方 ...

  4. 【转】STL中mem_fun和mem_fun_ref的用法及区别

    原文:http://www.cppblog.com/mysileng/archive/2012/12/25/196615.html 引子: 怎么对容器中的所有对象都进行同一个操作?我们可能首先想到的是 ...

  5. JavaScript 常用方法总结

    经常使用的 JS 方法,今天记下,以便以后查询 /* 手机类型判断 */ var BrowserInfo = { userAgent: navigator.userAgent.toLowerCase( ...

  6. (转)《深入理解java虚拟机》学习笔记6——类加载机制

    Java虚拟机类加载过程是把Class类文件加载到内存,并对Class文件中的数据进行校验.转换解析和初始化,最终形成可以被虚拟机直接使用的java类型的过程. 在加载阶段,java虚拟机需要完成以下 ...

  7. C语言基础(转载自大海笔记)

    # C语言基础2015年03月26日10:04:411.    语言排行榜C——java——objective-C2.    进制:进制:进位机制.用普通的话讲,应该为人为的定义一种度量来标识一样东西 ...

  8. Cocos-x 3.2:从C++过渡到Lua(转载)

    原文总结的非常好,都是我们学cocos2d-x以来摸索过的东西,如果早有这篇文章就能少走不少弯路了,特此截屏保存.原文链接:http://shahdza.blog.51cto.com/2410787/ ...

  9. FormBorderStyle.None 时候最大化不遮盖任务栏

    this.FormBorderStyle = FormBorderStyle.None;             this.MaximumSize = new Size(Screen.PrimaryS ...

  10. Samba出现“您可能没有权限使用网络资源”解决方法

    我最近在Centos6.3上搭建Samba系统,按照配置都已经配置好了,当就是没法在win7下访问,老是弹出以下弹出框: 后来我在网上找资料发现有SELinux这么个东西,然后我就按照配置该了一下就成 ...