题目链接:

Super Mario

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 32768/32768 K (Java/Others)

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
 
题意:
 
给定一个数列.给区间[l,r]问此区间内<=k的数目是多少;
 
 
思路:
 
可以用树状数组离线处理,把原序列按从小到大排序,询问也按k的大小排序,然后一边询问一边update;最近学了划分树,也可以做这题,看明天有时间想一想怎么做吧;
 
AC代码:
 
/*
树状数组的代码:
4417 202MS 3744K 1873 B G++ 2014300227 */ #include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N],n,m,sum[N],ans[N];
struct node
{
friend bool operator< (node x,node y)
{
if(x.num == y.num)return x.pos < y.pos;
return x.num < y.num;
}
int l,r,pos,num;
};
node po[N];
struct nod
{
friend bool operator< (nod x,nod y)
{
if(x.a==y.a)return x.pos<y.pos;
return x.a<y.a;
}
int a,pos;
};
nod p[N];
int lowbit(int x)
{
return x&(-x);
}
void update(int x)
{
while(x<=n)
{
sum[x]++;
x+=lowbit(x);
}
}
int query(int x)
{
int s=;
while(x>)
{
s+=sum[x];
x-=lowbit(x);
}
return s;
}
int main()
{
int t;
scanf("%d",&t);
int cnt=;
while(t--)
{
memset(sum,,sizeof(sum));
printf("Case %d:\n",cnt++);
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&p[i].a);
p[i].pos=i;
}
sort(p+,p+n+);
for(int i=;i<m;i++)
{
scanf("%d%d%d",&po[i].l,&po[i].r,&po[i].num);
po[i].l++;
po[i].r++;
po[i].pos=i;
}
sort(po,po+m);
int fp=;
for(int i=;i<m;i++)
{
if(p[fp].a<=po[i].num)
{
while(p[fp].a<=po[i].num&&fp<=n)
{
update(p[fp].pos);
fp++;
}
}
if(po[i].l==)ans[po[i].pos]=query(po[i].r);
else
{
ans[po[i].pos]=query(po[i].r)-query(po[i].l-);
}
}
for(int i=;i<m;i++)
{
printf("%d\n",ans[i]);
} } return ;
}

hdu-4417 Super Mario(树状数组 + 划分树)的更多相关文章

  1. hdu 1166:敌兵布阵(树状数组 / 线段树,入门练习题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. 树状数组 && 线段树应用 -- 求逆序数

    参考:算法学习(二)——树状数组求逆序数 .线段树或树状数组求逆序数(附例题) 应用树状数组 || 线段树求逆序数是一种很巧妙的技巧,这个技巧的关键在于如何把原来单纯的求区间和操作转换为 求小于等于a ...

  3. hdu1394(枚举/树状数组/线段树单点更新&区间求和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给出一个循环数组,求其逆序对最少为多少: 思路:对于逆序对: 交换两个相邻数,逆序数 +1 ...

  4. 【BZOJ-1452】Count 树状数组 套 树状数组

    1452: [JSOI2009]Count Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1769  Solved: 1059[Submit][Stat ...

  5. zoj2112 树状数组+主席树 区间动第k大

    Dynamic Rankings Time Limit: 10000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Subm ...

  6. BZOJ_1901_Zju2112 Dynamic Rankings_树状数组+主席树

    BZOJ_1901_Zju2112 Dynamic Rankings_树状数组+主席树 题意: 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i, ...

  7. Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分)

    Luogu 2680 NOIP 2015 运输计划(树链剖分,LCA,树状数组,树的重心,二分,差分) Description L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之 ...

  8. 洛谷P2414 阿狸的打字机 [NOI2011] AC自动机+树状数组/线段树

    正解:AC自动机+树状数组/线段树 解题报告: 传送门! 这道题,首先想到暴力思路还是不难的,首先看到y有那么多个,菜鸡如我还不怎么会可持久化之类的,那就直接排个序什么的然后按顺序做就好,这样听说有7 ...

  9. 【BZOJ】1047: [HAOI2007]理想的正方形(单调队列/~二维rmq+树状数组套树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1047 树状数组套树状数组真心没用QAQ....首先它不能修改..而不修改的可以用单调队列做掉,而且更 ...

随机推荐

  1. c# out ref

    out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out 关键字.例如 ...

  2. 将C#文档注释生成.chm帮助文档(转)

    由于最近需要把以前的一个项目写一个文档,但一时又不知道写成怎样的,又恰好发现了可以生成chm的工具,于是乎我就研究了下,感觉还不错,所以也给大家分享下.好了,不多废话,下面就来实现一下吧. 生成前的准 ...

  3. 1verilog 位拼接

    位拼接还可以用重复法来简化表达式.见下例: {4{w}}             //这等同于{w,w,w,w} 位拼接还可以用嵌套的方式来表达.见下例: {b,{3{a,b}}}     //这等同 ...

  4. sphinx PDF 中文

    使用reST撰写文档时,需要分多个文档时,就必须使用sphinx了,sphinx说起来很简单的,但是默认是不是支持中文的.幸好我出生的晚,sphinx现在已经支持xelatex了^_^ 安装 除了pa ...

  5. Zend API:深入 PHP 内核

    Introduction Those who know don't talk. Those who talk don't know. Sometimes, PHP "as is" ...

  6. PHP面向对象——构造函数、析构函数

    在PHP中构造函数和析构函数是固定的,如下: // 构造函数 function __construct([argument1,argument2,...,argumentN]){ /* Class i ...

  7. 深入Asyncio(六)Tasks and Futures

    Tasks and Futures 大多数的工作只涉及到Task.create_task()方法,就像前面代码一样,Future是Task的父类,提供与loop交互的所有功能. Future对象表示某 ...

  8. Linux下比较常用的svn命令

    svn: command not found yum install -y subversion 以下是一些常用命令的使用方法,希望对大家有所帮助. 1,check out(co)签出代码 test. ...

  9. Spring Boot: 加密应用配置文件敏感信息

    Spring Boot: 加密应用配置文件敏感信息 背景 我们的应用之前使用的是Druid数据库连接池,由于需求我们迁移到HikariCP连接池,druid 数据源加密提供了多种方式: 可以在配置文件 ...

  10. Java&amp;Xml教程(十)XML作为属性文件使用

    我们一般会将Java应用的配置參数保存在属性文件里.Java应用的属性文件能够是一个正常的基于key-value对,以properties为扩展名的文件.也能够是XML文件. 在本案例中.將会向大家介 ...