题目链接:

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. prop()方法和attr()方法以及区别

    prop()方法: prop() 方法设置或返回被选元素的属性和值. 当该方法用于返回属性值时,则返回第一个匹配元素的值. 当该方法用于设置属性值时,则为匹配元素集合设置一个或多个属性/值对. 注意: ...

  2. 处理字符串的一些C函数

    注意:以下函数都包含在ctype.h头文件中 1.isalpha函数 用来判断得到的参数是不是字母 #include<stdio.h> #include<ctype.h> in ...

  3. unslider点导航不显示错误

    原因是,unslider插件只添加了dots文件并没有设置样式 解决办法 .banner { position: relative; width: 100%; overflow: auto; font ...

  4. mysql忘记password

    有时候突然忘记MySQL的password会真的不爽,这里介绍一种MySQLpassword忘记时重置password的方法,操作系统win8,MySql version:5.6.10 1 在任务管理 ...

  5. 禁用android studio自身的ndk编译disable automatic ndk-build call

    1,让studio不自动编译jni文件,而是我们手动通过ndk-build编译    打开工程下面的app文件夹, 找到build.gradle   添加如下:  defaultConfig {   ...

  6. C语言的运算符的优先级与结合性+ASCII表

    [0]README 0.1) 内容来源于 C程序设计语言, 旨在整理出C语言的运算符的优先级与结合性, 如下图所示(哥子 记了大半年都没有记住,也是醉了,每次都要去翻): Alert)以下内容转自:h ...

  7. iOS中用UIWebView的loadHTMLString后图片和文字失调解决方法

    iOS中用UIWebView的loadHTMLString后图片和文字失调,图片过大,超过屏幕,文字太小.或者图片太小.文字太大,总之就是不协调. 我们的需求是让图片的大小跟着屏幕的变化而变化.就是动 ...

  8. ios math.h 常用数学函数

    1. 三角函数  double sin (double);正弦  double cos (double);余弦  double tan (double);正切  2 .反三角函数  double as ...

  9. 【Java并发编程实战】—–“J.U.C”:ReentrantLock之二lock方法分析

    前一篇博客简介了ReentrantLock的定义和与synchronized的差别,以下尾随LZ的笔记来扒扒ReentrantLock的lock方法.我们知道ReentrantLock有公平锁.非公平 ...

  10. Java 学习 day05

    01-面向对象(概述) 面向对象 -- 冰箱.打开:冰箱.存储:冰箱.关闭: 02-面向对象(举例) 使用和指挥 -- 对象,不需要关注过程,只关注结果: 一切皆对象,万物皆对象  -- 自<T ...