题目链接:

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. 【转载】ASP.Net WebForm温故知新学习笔记:一、aspx与服务器控件探秘

    开篇:毫无疑问,ASP.Net WebForm是微软推出的一个跨时代的Web开发模式,它将WinForm开发模式的快捷便利的优点移植到了Web开发上,我们只要学会三步:拖控件→设属性→绑事件,便可以行 ...

  2. fabric使用实例(发布web包的一个例子)

    #!/usr/bin/env python # -*- coding: utf-8 -* #添加中文注释的编码 #fabfile.py from fabric.api import * env.use ...

  3. myql5.7.7优化配置參数

    # Other default tuning values # MySQL Server Instance Configuration File # ------------------------- ...

  4. JAVA学习第二十五课(多线程(四))- 单例设计模式涉及的多线程问题

    一.多线程下的单例设计模式 利用双重推断的形式解决懒汉式的安全问题和效率问题 //饿汉式 /*class Single { private static final Single t = new Si ...

  5. linux下安装最新版Subversion 1.8.9

    linux下安装最新版subversion,代码: [root@localhost subversion-1.8.9]# ./configure --prefix=/usr/local/subvers ...

  6. iOS自己定义对象保存到本地文件

    我是将聊天记录存到本地,里边用到了自己定义的对象.把数据转成Data格式存到本地.在转Data格式的时候报错了.这时候须要先将自己定义对象进行归档才干够转Data格式. 方法例如以下: 一.在.h文件 ...

  7. Gunicorn、Supervisor

    简介 Gunicorn来源于Ruby的unicorn项目,是一个Python WSGI HTTP Server,通过pre-fork worker模型来管理和维护worker. 简而言之就是通过多进程 ...

  8. 【转】windows下 ADT NDK开发环境配置

    前提: 下载好Ecplise ADT并配置好开发环境,不会配置环境可以参考这里: http://blog.csdn.net/danfengw/article/details/47111107 步骤: ...

  9. MySQL 创建自定义函数(2)

    说明:下面创建一个函数,调用自定义函数返回一个返回一个随机数. (1) 创建自定义函数

  10. mongodb.py

    from chatterbot.storage import StorageAdapter class Query(object): def __init__(self, query={}): sel ...