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 ...
随机推荐
- postman测试传入json
- thinkcmf5增加微信管理app笔记
simplewind/extend/目录下增加 EasyWeChat Monolog //是PHP的一个日志类库 https://segmentfault.com/a/1190000002775 ...
- 科学计算库Numpy——numpy.ndarray
创建ndarray 元素类型 对于ndarray结构来说,里面所有的元素必须是同一类型的,如果不是的话,会自动的向下进行转换. 元素类型所占字节数 数组维数 元素个数 数组的维度 数组中填充固定值 索 ...
- 小谈python里 列表 的几种常用用法
在python中列表的常用方法主要包括增加,删除,查看和修改.下面以举例子的方法具体说明,首先我们创建两个列表,列表是用[ ]表示的,里面的元素用逗号隔开. a=[‘hello’,78,15.6,‘你 ...
- huu 1251
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- 【草稿】JS中如何操作时间
如何声明时间变量 如何设置时间变量的时.分.秒.毫秒 如何根据字符串变量,声明指定的时间变量 如何比较两个时间变量 代码如下: $(function () { var d = new Date(); ...
- while True 死循环
while True 死循环示例: count = 0 #给count设置变量为0 while True: count += 1 #每循环一次,count+1 : count += 1 等同于coun ...
- JAVA里的别名机制
别名现象主要出现在赋值的问题上: 对基本数据类型的赋值是很简单的.基本数据类型存储了实际的数值,而并非指向一个对象的引用,所以在为其赋值的时候,是直接将一个地方的内容复制到了另一个地方.例如,对基本数 ...
- Hadoop4.2HDFS测试报告之三
第一组:文件存储写过程记录 NameNode:1 DataNode:1 本地存储 scp localpath romotepath 500 2 1 23.67 NameNode:1 DataNode: ...
- 安装go 1.5 & 部署
https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz tar -C /usr/local -xzf go1.5.linux-am ...