Super Mario
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
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.)
Output
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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[maxn],b[maxn*],s[maxn*],ls[maxn*],rs[maxn*],root[maxn*],sz;
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct node
{
int x,y,z;
node(){}
node(int _x,int _y,int _z):x(_x),y(_y),z(_z){}
}op[maxn];
void insert(int l,int r,int x,int &y,int v)
{
y=++sz;
s[y]=s[x]+;
if(l==r)return;
ls[y]=ls[x],rs[y]=rs[x];
int mid=l+r>>;
if(v<=mid)insert(l,mid,ls[x],ls[y],v);
else insert(mid+,r,rs[x],rs[y],v);
}
int query(int l,int r,int L,int R,int x,int y)
{
if(l==L&&r==R)return s[y]-s[x];
int mid=L+R>>;
if(r<=mid)return query(l,r,L,mid,ls[x],ls[y]);
else if(l>mid)return query(l,r,mid+,R,rs[x],rs[y]);
else return query(l,mid,L,mid,ls[x],ls[y])+query(mid+,r,mid+,R,rs[x],rs[y]);
}
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
sz=;
scanf("%d%d",&n,&m);
rep(i,,n)a[i]=read(),b[i]=a[i];
rep(i,,m)
{
int c,d,e;
c=read(),d=read(),e=read();
c++,d++;
b[i+n]=e;
op[i]=node(c,d,e);
}
printf("Case %d:\n",++k);
sort(b+,b+n+m+);
int num=unique(b+,b+n+m+)-b-;
rep(i,,n)
{
a[i]=lower_bound(b+,b+num+,a[i])-b;
insert(,num,root[i-],root[i],a[i]);
}
rep(i,,m)
{
int x=op[i].x,y=op[i].y,z=op[i].z;
z=lower_bound(b+,b+num+,z)-b;
printf("%d\n",query(,z,,num,root[x-],root[y]));
}
}
//system("Pause");
return ;
}
Super Mario的更多相关文章
- HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learning Project
Teaching Your Computer To Play Super Mario Bros. – A Fork of the Google DeepMind Atari Machine Learn ...
- hdu4177:Super Mario
主席树+离散化.给一段区间.多次询问[l,r]中有多少个数小于k.啊主席树用指针版写出来优美多了QAQ... #include<cstdio> #include<cstring> ...
- 主席树:HDU 4417 Super Mario
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu4417 Super Mario 树阵离线/划分树
http://acm.hdu.edu.cn/showproblem.php?pid=4417 Super Mario Time Limit: 2000/1000 MS (Java/Others) ...
- hdu4417(Super Mario)—— 二分+划分树
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 4417 Super Mario 树状数组||主席树
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- HDU 4417 Super Mario(线段树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 4417 Super Mario(划分树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- 阅读http://zh.lucida.me/有感
lucida大神本科毕业于大工,研究生毕业于北航,有这样的学历在社会上混就已经绰绰有余了,但是lucida神并不满足,刻苦努力,拼搏进取,最后进入google london工作,曾经一度在micros ...
- viewPager的切换动画
今天在看苏州通的代码,里面有个引导的代码,涉及到viewPager的切换动画: DepthPageTransformer : package com.soyoungboy.guide; import ...
- iOS打上线包或者测试包详细流程
首先登陆苹果官方开发者账号:http://developer.apple.com 进入到如下界面 之后进入如下界面:点击第二项创建证书 整个流程如下图4步 然后按照如下图片进行配置即可 接下来去创建C ...
- hdu_5690_All X(找循环节)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5690 题意: Problem Description F(x, m)F(x,m) 代表一个全是由数字x ...
- 第一个WebAPI项目
(1)新建一个ASP.NET MVC项目,取名为:MyMvcWebAPIDemo,项目类型选择WebAPI. (2)在Models中新增一个类,取名为:Product,作为我们要测试的实体模型. ...
- 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.googleplay.ui.activity.MainActivity" on path: DexPathList[[zip file "/data/app/c
一运行,加载mainActivity就报错 布局文件乱写一通,然后急着运行,报莫名其妙的错误: 07-09 07:28:38.350: E/AndroidRuntime(1437): Caused b ...
- sql定期移植数据的存储过程
create PROCEDURE [dbo].[Pro_ZT_SYS_LogInfo_clear] @dt_end datetime --清理此日期之前的数据 AS BEGIN SET NOCOUNT ...
- spring XML格式
使用spring遇见一个很坑的问题,在XML中 这样配置: <method name="newSoapParam2" parameters="java.lang.S ...
- 上海赛趣-top.mainFrame.tabAddHandler方法详解
top.mainFrame.tabAddHandler("item"+Id,'项目:'+itemname,'<%=basePath%>bizitem/goEditIte ...
- 安装MSYS2过程遇到的问题及解决记录
1.在安装结束后按照官方教程开始更新系统是遇到了如下的错误 could not open file /var/lib/pacman/sync/msys32.db: Unrecognized archi ...