HDU-4417-Super Mario(线段树+离线处理)
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
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 代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std; struct node
{
int l,r;
int num;
}tree[maxn<<]; struct node1
{
int pos,l,r,h;
bool friend operator <(node1 x, node1 y)
{
return x.h<y.h;
}
}h[maxn];
struct node2
{
int pos,h;
bool friend operator <(node2 x,node2 y)
{
return x.h<y.h;
}
}p[maxn]; void pushup(int m)
{
tree[m].num=(tree[m<<].num+tree[m<<|].num);
return;
}
void build(int m,int l,int r)
{
tree[m].l=l;
tree[m].r=r;
tree[m].num=;
if(l==r)
{
return ;
}
int mid=(tree[m].l+tree[m].r)>>;
build(m<<,l,mid);
build(m<<|,mid+,r);
return;
}
void update(int m,int index,int val)
{
if(tree[m].l==index&&tree[m].l==tree[m].r)
{
tree[m].num=val;
return ;
}
int mid=(tree[m].l+tree[m].r)>>;
if(index<=mid)
{
update(m<<,index,val);
}
else
{
update(m<<|,index,val);
}
pushup(m);
return ;
}
int query(int m,int l,int r)
{
if(tree[m].l==l&&tree[m].r==r)
{
return tree[m].num;
}
int mid=(tree[m].l+tree[m].r)>>;
if(r<=mid)
{
return query(m<<,l,r);
}
else if(l>mid)
{
return query(m<<|,l,r);
}
else
{
return query(m<<,l,mid)+query(m<<|,mid+,r);
}
}
int a[maxn];
int main()
{
int T;
cin>>T;
for(int k=;k<=T;k++)
{
int n,m;
scanf("%d%d",&n,&m);
for(int t=;t<=n;t++)
{
scanf("%d",&p[t].h);
p[t].pos=t;
}
for(int t=;t<=m;t++)
{
scanf("%d%d%d",&h[t].l,&h[t].r,&h[t].h);
h[t].l++;
h[t].r++;
h[t].pos=t;
} printf("Case %d:\n",k);
build(,,n);
sort(p+,p+n+);
sort(h+,h+m+);
int j=;
int s=;
while(s<=n)
{
if(p[s].h>h[j].h)
{
// cout<<h[j].l<<" "<<h[j].r<<endl;
a[h[j].pos]=query(,h[j].l,h[j].r);
j++;
if(j>m)
{
break;
}
}
else
{
update(,p[s].pos,);
s++;
}
}
while(j<=m)
{
a[h[j].pos]=query(,h[j].l,h[j].r);
j++;
}
for(int t=;t<=m;t++)
{
printf("%d\n",a[t]);
}
} return ;
}
HDU-4417-Super Mario(线段树+离线处理)的更多相关文章
- HDOJ 4417 - Super Mario 线段树or树状数组离线处理..
题意: 同上 题解: 抓着这题作死的搞~~是因为今天练习赛的一道题.SPOJ KQUERY.直到我用最后一种树状数组通过了HDOJ这题后..交SPOJ的才没超时..看排名...时间能排到11名了..有 ...
- HDU 4417 Super Mario(划分树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4417 Super Mario(划分树问题求不大于k的数有多少)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4417 Super Mario 主席树查询区间小于某个值的个数
#include<iostream> #include<string.h> #include<algorithm> #include<stdio.h> ...
- HDU 4417 - Super Mario ( 划分树+二分 / 树状数组+离线处理+离散化)
题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案. ...
- HDU 4417 Super Mario 主席树
分析:找一个区间里小于等于h的数量,然后这个题先离散化一下,很简单 然后我写这个题主要是熟悉一下主席树,其实这个题完全可以离线做,很简单 但是学了主席树以后,我发现,在线做,一样简单,而且不需要思考 ...
- HDU 4417 Super Mario(划分树+二分)
题目链接 #include <cstdio> #include <cstring> #include <algorithm> using namespace std ...
- HDU 4417 Super Mario(2012杭州网络赛 H 离线线段树)
突然想到的节约时间的方法,感觉6翻了 给你n个数字,接着m个询问.每次问你一段区间内不大于某个数字(不一定是给你的数字)的个数 直接线段树没法做,因为每次给你的数字不一样,父节点无法统计.但是离线一 ...
- hdu 4417 Super Mario 离线线段树
思路:将点按值从小到大排序,询问按h从小到大排序. 在建立线段树,按h的大小更新树并得到该次查询的结果! 代码如下: #include<iostream> #include<stdi ...
- HDU 4417 Super Mario(线段树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- CentOS 7.0防火墙设置
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙.1.关闭firewall:systemctl stop firewalld.servicesystemctl ...
- Python玩转各种多媒体,视频、音频到图片
我们经常会遇到一些对于多媒体文件修改的操作,像是对视频文件的操作:视频剪辑.字幕编辑.分离音频.视频音频混流等.又比如对音频文件的操作:音频剪辑,音频格式转换.再比如我们最常用的图片文件,格式转换.各 ...
- 2020-05-14:实现分布式Session的过程是怎样的?
福哥答案2020-05-14: 此答案来自群员:分布式session ,最开始起源是双机热备,当时php1和php2为了共享session,一开始采用samba/nfs,后来php有了插件以后就扔当时 ...
- C#设计模式之5-单例模式
单例模式(Singleton Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/397 访问. 单例模式属 ...
- C#算法设计排序篇之07-希尔排序(附带动画演示程序)
希尔排序(Shell's Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/687 访问. 希尔排序是插入排序的 ...
- 看DLI服务4核心如何提升云服务自动化运维
摘要:今天我们来说说DLI是如何实现监控告警来提升整体运维能力,从而为客户更好的提供Serverless的DLI. DLI是支持多模引擎的Serverless大数据计算服务,免运维也是其作为Serve ...
- Python对list操作的一些小技巧
Python对list操作的一些小技巧 由于要搞数学建模,于是从熟悉已久的C++转战Python.虽然才上手,但是Python的语法糖就让我大呼过瘾.不得不说相比于C/C++,Python对于数据的 ...
- 痞子衡嵌入式:利用i.MXRT1060,1010上新增的FlexSPI地址重映射(Remap)功能可安全OTA
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是i.MXRT部分型号上新增的FlexSPI Remap功能. OTA升级设计几乎是每个量产客户都绕不开的话题,产品发布后免不了要做固件( ...
- vue报错vue-router.esm.js?8c4f:2007 Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}
今天在写vue项目配置好路由点击菜单时,突然在控制台报错. 错误信息如下: Uncaught (in promise) NavigationDuplicated {_name: "Navig ...
- Visual Studio自动编译gRPC工程的设置
前段时间研究一个java程序,增加一些功能.其中用到java和C#的通信.自然,有多种办法,后来实际上是用javascript调用C#的REST WCF服务实现的.但是在查资料的过程中,发现有个Pro ...