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 ...
随机推荐
- Java的WatchService文件夹监听遇到的一些问题
打开word文档时会新增一个~$开头的同名文件,关闭时该文件自动删除 修改excel文件时,会新增一个文件名像E56B4610,CBC15610等这样的文件,同时也会产生tmp格式的文件 PPT文件修 ...
- 编译-LAMP基于fastcgi
前言 最近没更新新篇幅了,今天就来点干活,过多的也不说了下面着手干!干!干! 准备环境 centos7.5 apr-1.6.3.tar.gz apr-util-1.6.1.tar.gz h ...
- python入门:while 循环的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #while 循环的作用 import time while True: ") time.sleep ...
- PHP redis使用命令
很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://github.com/owlient/phpredis(支持redis 2.0.4) Redis::__constru ...
- 9-11.Yii2.0框架控制器分配视图并传参xss攻击脚本视图的过滤
目录 一维数组传参 新建控制器: 新建view模板 二维数组传参 新建控制器: 新建view模板 视图非法字符的过滤 新建控制器: 新建view模板 一维数组传参 新建控制器: D:\xampp\ht ...
- 数字pid笔记(1)
针对stm32中可以如下实现: p->IncrementVal = (p->Kp * (p->err - p->err_next)) + (p->Ki * p->e ...
- 合肥工业大学宣城校区大学生创新创业训练项目申报书:“基于Spark平台的人工智能知识的知识图谱构建”
- cobbler 安装centos7.3时GPT问题(五)
磁盘分区表MBR和GPT介绍: MBR(Master Boot Record):最大只支持2 TB的盘,最多只支持4个主分区,信息只存储在一个区域. GPT(GUID partition table) ...
- spring scope 属性的取值
Spring 容器是通过单例模式创建 Bean 对象的,也就是说,默认情况下,通过调用 ac.getBean("mybean")方法获得的对象都是同一个 mybean 对象 使用单 ...
- POJ 2181 Jumping Cows
Jumping Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6398 Accepted: 3828 Desc ...