AC日记——Super Mario hdu 4417
Super Mario
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6122    Accepted Submission(s):
2660
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.
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.)
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.
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
4
0
0
3
1
2
0
1
5
1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 100005 using namespace std; struct TreeNodeType {
int lc,rc,dis;
};
struct TreeNodeType tree[maxn*]; int if_z,t,n,m,num[maxn],Hash[maxn],size,cnt,root[maxn]; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} void tree_build(int &now,int l,int r)
{
now=++cnt,tree[now].dis=;
if(l==r) return ;
int mid=(l+r)>>;
tree_build(tree[now].lc,l,mid);
tree_build(tree[now].rc,mid+,r);
} void tree_add(int pre,int &now,int to,int l,int r)
{
now=++cnt;
tree[now].dis=tree[pre].dis+;
if(l==r) return ;
int mid=(l+r)>>;
if(to<=mid)
{
tree_add(tree[pre].lc,tree[now].lc,to,l,mid);
tree[now].rc=tree[pre].rc;
}
else
{
tree_add(tree[pre].rc,tree[now].rc,to,mid+,r);
tree[now].lc=tree[pre].lc;
}
} int find(int x)
{
int l=,r=size,mid,ans;
while(l<=r)
{
mid=(l+r)>>;
if(x<=Hash[mid]) ans=mid,r=mid-;
else l=mid+;
}
return ans;
} int tree_query(int pre,int now,int to,int l,int r)
{
if(l==r) return tree[now].dis-tree[pre].dis;
int pos=tree[tree[now].lc].dis-tree[tree[pre].lc].dis;
int mid=(l+r)>>;
if(to<=mid) return tree_query(tree[pre].lc,tree[now].lc,to,l,mid);
else return pos+tree_query(tree[pre].rc,tree[now].rc,to,mid+,r);
} int main()
{
in(t);
for(int Case=;Case<=t;Case++)
{
in(n),in(m);cnt=;
for(int i=;i<=n;i++) in(num[i]),Hash[i]=num[i];
sort(Hash+,Hash+n+);
size=unique(Hash+,Hash+n+)-Hash-;
tree_build(root[],,size);
for(int i=;i<=n;i++)
{
num[i]=lower_bound(Hash+,Hash+size+,num[i])-Hash;
tree_add(root[i-],root[i],num[i],,size);
}
printf("Case %d:\n",Case);
int u,v,w;
while(m--)
{
in(u),in(v),in(w);
if(w<Hash[])
{
printf("0\n");
continue;
}
int pos=find(w);
if(Hash[pos]>w) pos--;
printf("%d\n",tree_query(root[u],root[v+],pos,,size));
}
}
return ;
}
AC日记——Super Mario hdu 4417的更多相关文章
- Super Mario HDU 4417 主席树区间查询
		
Super Mario HDU 4417 主席树区间查询 题意 给你n个数(编号从0开始),然后查询区间内小于k的数的个数. 解题思路 这个可以使用主席树来处理,因为这个很类似查询区间内的第k小的问题 ...
 - J - Super Mario HDU - 4417  线段树 离线处理 区间排序
		
J - Super Mario HDU - 4417 这个题目我开始直接暴力,然后就超时了,不知道该怎么做,直接看了题解,这个习惯其实不太好. 不过网上的思路真的很厉害,看完之后有点伤心,感觉自己应该 ...
 - Super Mario HDU - 4417 (主席树)
		
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...
 - Super Mario HDU - 4417 (主席树询问区间比k小的个数)
		
Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory ...
 - AC日记——Keywords Search hdu 2222
		
2222 思路: ac自动机模板题: 代码: #include <cstdio> #include <cstring> #include <iostream> #i ...
 - AC日记——Number Sequence hdu 1711
		
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
 - AC日记——统计难题 hdu 1251
		
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
 - AC日记——病毒侵袭 hdu 2896
		
2896 思路: 好题: 代码: #include <queue> #include <cstdio> #include <cstring> using names ...
 - AC日记——Paint Pearls hdu 5009
		
Paint Pearls 思路: 离散化+dp+剪枝: dp是个n方的做法: 重要就在剪枝: 如果一个长度为n的区间,有大于根号n种颜色,还不如一个一个涂: 来,上代码: #include <c ...
 
随机推荐
- 【Linux】开放指定端口设置
			
这里以开放tomcat的8080端口为例 1.开放Linux的8080端口 vi /etc/sysconfig/iptables 进入编辑页面,在指定位置新增以下配置 -A INPUT -m stat ...
 - EditPlus 比较完整的快捷键记录
			
FileFtpUpload Ctrl+Shift+S 上传文件到FTP 服务器 FileNew Ctrl+N 新建普通的文本文档 FileNewHtml Ctrl+Shift+N 创建一个空白的 HT ...
 - 百度地图和高德地图的API视频教程
			
学习地址: http://www.houdunren.com/houdunren18_lesson_152?vid=10228 素材地址: https://gitee.com/houdunwang/v ...
 - str 方法总结整理
			
#!/usr/bin/env python #Python 3.7.0 字符串常用方法 __author__ = "lrtao2010" #capitalize 将字符串的首字符改 ...
 - 使用python3调用MyQR库生成动态二维码(附源代码)
			
可生成普通二维码.带图片的艺术二维码(黑白与彩色).动态二维码(黑白与彩色). GitHub:https://github.com/sylnsfar/qrcode 中文版:https://github ...
 - ACM-ICPC 2018 徐州赛区网络预赛    F. Features Track
			
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
 - poj 2385 树上掉苹果问题 dp算法
			
题意:有树1 树2 会掉苹果,奶牛去捡,只能移动w次,开始的时候在树1 问最多可以捡多少个苹果? 思路: dp[i][j]表示i分钟移动j次捡到苹果的最大值 实例分析 0,1 1,2...说明 偶数 ...
 - 笔记-python-实用-程序运算时间计算
			
方法1 import datetime starttime = datetime.datetime.now() #long running endtime = datetime.datetime.no ...
 - BZOJ 2217: [Poi2011]Lollipop
			
若sum可行 sum-2一定可行 序列和为ans 找出和ans奇偶性不同的最大的ans,即最靠左或最靠右的1的位置 更新答案 有spj #include<cstdio> using nam ...
 - Python使用asyncio+aiohttp异步爬取猫眼电影专业版
			
asyncio是从pytohn3.4开始添加到标准库中的一个强大的异步并发库,可以很好地解决python中高并发的问题,入门学习可以参考官方文档 并发访问能极大的提高爬虫的性能,但是requests访 ...