Super Mario

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4046    Accepted Submission(s): 1866
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

题意:超级玛丽游戏的问题,很有意思。给你n个金币的高度(区间从0 - n-1)和m次查询,每次查询询问[l, r]里面小于或者等于h的金币数目。

思路:和树剖某一道题很像,sort下。把限制下的金币放里面,用个树状数组维护就好了。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (300000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while((a)--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
#pragma comment(linker, "/STACK:102400000,102400000")
#define fi first
#define se second
using namespace std;
int C[MAXN], n;
int lowbit(int x){return x & (-x);
}
void Update(int x, int d)
{while(x <= n){C[x] += d;x += lowbit(x);}
}
int Sum(int x)
{int s = 0;while(x > 0){s += C[x];x -= lowbit(x);}return s;
}
typedef pair<int, int> pii;
bool cmp1(pii a, pii b){return a.fi < b.fi;
}
vector<pii> G;
vector<pii> :: iterator it;
struct Node{int l, r, h, id;
};
Node In[MAXN];
bool cmp2(Node a, Node b){return a.h < b.h;
}
int ans[MAXN];
int main()
{int t, kcase = 1; Ri(t);W(t){int m; Ri(n); Ri(m); G.clear();for(int i = 1; i <= n; i++){int a; Ri(a);G.push_back(pii(a, i));}sort(G.begin(), G.end(), cmp1);for(int i = 1; i <= m; i++)Ri(In[i].l), Ri(In[i].r), Ri(In[i].h), In[i].id = i, In[i].l++, In[i].r++;sort(In+1, In+m+1, cmp2); CLR(C, 0); it = G.begin();for(int i = 1; i <= m; i++){while(it != G.end() && it->fi <= In[i].h) {Update(it->se, 1); it++;}ans[In[i].id] = Sum(In[i].r) - Sum(In[i].l-1);}printf("Case %d:\n", kcase++);for(int i = 1; i <= m; i++) Pi(ans[i]);}return 0;
}

hdoj 4417 Super Mario 【树状数组 + 思维】相关推荐

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

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

  2. 【树状数组 思维题】luoguP3616 富金森林公园

    树状数组.差分.前缀和.离散化 题目描述 博艾的富金森林公园里有一个长长的富金山脉,山脉是由一块块巨石并列构成的,编号从1到N.每一个巨石有一个海拔高度.而这个山脉又在一个盆地中,盆地里可能会积水,积 ...

  3. HDU - 5775 - Bubble Sort( 树状数组 + 思维 )

    题目链接:点击进入 题目 题意 问在给出的冒泡排序过程中,一个数到达的最右边位置与最左边位置距离差. 思路 对于一个数,位置 i ,假设右边比它小的数有 r 个,左边比它大的数有 l 个,最右边到达的 ...

  4. HDOJ 4417 Super Mario

    划分树+二分 Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. 牛客练习赛34 - C little w and Segment Coverage(思维、树状数组)

    title: 牛客练习赛34 - C little w and Segment Coverage(思维.树状数组) date: 2018-12-15 16:36:55 tags: [树状数组,思维] ...

  6. 【学习笔记+习题集】(树状数组)(9473字)

    目录 板块一:树状数组 引子:lowbit 1.存入数据(单点修改) 2.区间查询 练习1:hdoj1541 3.区间修改和单点查询(差分数组) 练习1:hdoj 1556 练习2:洛谷P3368 4 ...

  7. HDU 4417 Super Mario(莫队 + 树状数组 + 离散化)

    Super Mario 思路 区间查找问题,容易想到离线莫队,确实这题就是莫队,接下来我们考虑如何维护区间高度值问题. 既然是离线嘛,我们容易想到离散化和他挂钩,想想这题是否需要离散化,高度的最大值是 ...

  8. HDU 4417 Super Mario(线段树||树状数组+离线操作 之线段树篇)

    Mario is world-famous plumber. His "burly" figure and amazing jumping ability reminded in ...

  9. HDU 4417 Super Mario(离线线段树or树状数组)

    Problem Description Mario is world-famous plumber. His "burly" figure and amazing jumping ...

最新文章

  1. 皮一皮:21世纪了还有这样的事情?
  2. php接收一维数组中文乱码解决
  3. 发达国家农业模式-国际农民丰收节贸易会:全球农业未来
  4. 收集下阿里集团下的技术BLOG
  5. abap 取数排序之后怎么取第一行
  6. Redis 基本数据类型 :String、Hash、List、Set、ZSet
  7. 电脑控制iphone_如何把苹果 iPhone/iPad 投屏到电脑
  8. 沃谈小知识|可“防拆”的远程锁机
  9. WINDOWS系统下四叶草CLOVER引导U盘制作
  10. 计算机不驱动u盘启动,电脑U盘驱动没有启用的解决方法
  11. 3 Java 基础__不同数据类型之间的运算及进制
  12. docx文件是什么?如何打开后缀名.docx格式的word2007文件?
  13. java中间件技术有哪些?
  14. poi在pptx中动态刷新已经存在的图
  15. pika的原理和实现
  16. 一种全新的指令集架构RISC-V
  17. GM65与stm32通信
  18. RecurDyn在PNet二次开发Run时所遇到的异常
  19. Linux开发环境相关包的下载路径
  20. Python 之使用模板生成周报

热门文章

  1. QQ小程序支付 调起微信支付
  2. 【PHP】获取浏览器HTTP请求header信息、获取服务器HTTP响应header信息
  3. 解决Windows环境下PHP连接MySQL很慢的问题
  4. 联想微型计算机m4350q升级,细节:联想M4350q小巧到极致_联想ThinkCentre台式电脑_台式电脑评测-中关村在线...
  5. 最简单的个人辞职原因[范文7篇]
  6. Firefox启动自带翻译
  7. 产品化与项目之间的关系
  8. iOS 修改苹果开发者公司账号(Apple ID 更换)
  9. LEFT OUTER JOIN 使用实例
  10. 【持续更新】2001-2022历代AMD 工作站桌面显卡列表,工作站显卡发布日期