博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU-4417 Super Mario
阅读量:5067 次
发布时间:2019-06-12

本文共 2939 字,大约阅读时间需要 9 分钟。

Super Mario

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.

InputThe 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.)OutputFor 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

110 100 5 2 7 5 4 3 8 7 7 2 8 63 5 01 3 11 9 40 1 03 5 55 5 14 6 31 5 75 7 3

Sample Output

Case 1:4003120151

 题意:求区间[l-r]的<=k的个数

裸的主席树,离散化一下就行了。

#include
using namespace std;#define Debug(x) cout<<#x<<":"<<(x)<
>1; build(l,m,tree[x].l); build(m+1,r,tree[x].r); pushup(x);}int query(int l,int r,int pre,int now,int x,int y){ if(x<=l&&r<=y) return tree[now].num-tree[pre].num; int m=(l+r)>>1; int ans=0; if(x<=m) ans+=query(l,m,tree[pre].l,tree[now].l,x,y); if(y>m) ans+=query(m+1,r,tree[pre].r,tree[now].r,x,y); return ans;}void updata(int l,int r,int pre,int &now,int k){ now=++cnt; tree[now]=tree[pre]; if(l==r) { tree[now].num++; return ; } int m=(l+r)>>1; if(k<=m) updata(l,m,tree[pre].l,tree[now].l,k); else updata(m+1,r,tree[pre].r,tree[now].r,k); pushup(now);}int main(){ int n,m,t,p=1; scanf("%d",&t); while(t--) { printf("Case %d:\n",p++); scanf("%d %d",&n,&m); { cnt=0; for(int i=1; i<=n; i++) scanf("%d",&a[i]),b[i]=a[i]; sort(b+1,b+1+n); int len=unique(b+1,b+1+n)-(b+1); for(int i=1; i<=n; i++) a[i]=lower_bound(b+1,b+1+len,a[i])-b; build(1,len,rt[0]); for(int i=1; i<=n; i++) updata(1,len,rt[i-1],rt[i],a[i]); while(m--) { int l,r,k1,k; scanf("%d %d %d",&l,&r,&k); l++; r++; k1=lower_bound(b+1,b+1+len,k)-b; if(b[k1]!=k) k1--; if(k1==0)//不判断会出现MLE { printf("0\n"); continue; } printf("%d\n",query(1,len,rt[l-1],rt[r],1,k1)); } } }}

 

 

 

PS:摸鱼怪的博客分享,欢迎感谢各路大牛的指点~

转载于:https://www.cnblogs.com/MengX/p/9104963.html

你可能感兴趣的文章
【AS3代码】播放FLV视频流的三步骤!
查看>>
枚举的使用
查看>>
luogu4849 寻找宝藏 (cdq分治+dp)
查看>>
日志框架--(一)基础篇
查看>>
关于源程序到可运行程序的过程
查看>>
转载:mysql数据库密码忘记找回方法
查看>>
scratch少儿编程第一季——06、人在江湖混,没有背景怎么行。
查看>>
【贪心+DFS】D. Field expansion
查看>>
C# Async与Await的使用
查看>>
Mysql性能调优
查看>>
iOS基础-UIKit框架-多控制器管理-实例:qq界面框架
查看>>
自定义tabbar(纯代码)
查看>>
小程序底部导航栏
查看>>
ibatis学习笔记
查看>>
18-ES6(1)
查看>>
poj1611 简单并查集
查看>>
Ubuntu 14.04下安装CUDA8.0
查看>>
跨平台开发 -- C# 使用 C/C++ 生成的动态链接库
查看>>
C# BS消息推送 SignalR介绍(一)
查看>>
WPF星空效果
查看>>