Super Mario

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Mario is world-famous plumber. His “burly” figure and 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.

Input

The 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.)

Output

For
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的更多相关文章

  1. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. 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 ...

  3. hdu4177:Super Mario

    主席树+离散化.给一段区间.多次询问[l,r]中有多少个数小于k.啊主席树用指针版写出来优美多了QAQ... #include<cstdio> #include<cstring> ...

  4. 主席树:HDU 4417 Super Mario

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu4417 Super Mario 树阵离线/划分树

    http://acm.hdu.edu.cn/showproblem.php?pid=4417 Super Mario Time Limit: 2000/1000 MS (Java/Others)    ...

  6. hdu4417(Super Mario)—— 二分+划分树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. hdu 4417 Super Mario 树状数组||主席树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  8. HDU 4417 Super Mario(线段树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  9. HDU 4417 Super Mario(划分树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. Strusts2--课程笔记5

      数据验证: 输入验证分为客户端验证与服务器端验证.客户端验证主要通过JavaScript脚本进行,而服务器端验证主要是通过Java代码进行验证. 分为以下四种情况: (1)手工编写代码,对所有Ac ...

  2. Flask -- 请求、上传文件、Cookies

    请求对象 from flask import request request.method #值为form表单提交的method 'POST'. 'GET'等 #如果值为'POST'或'PUT',则可 ...

  3. memcached + php 扩展 for ubuntu

    1.安装memcached apt-get install memcached 2.安装php memcached 扩展 apt-get install php5-memcache 3.启动memca ...

  4. oracle 同义词

    同义词概念 Oracle的同义词(synonyms)从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系.它可以节省大量的数据库空间,对不同用户的操作同一张表没有多少差别;它扩展了数据库的使 ...

  5. Android 内存监测工具 DDMS --> Heap(转)

    DDMS 的全称是Dalvik Debug Monitor Service,它为我们提供例如:为测试设备截屏,针对特定的进程查看正在运行的线程以及堆信息.Logcat.广播状态信息.模拟电话呼叫.接收 ...

  6. Chapter 1 First Sight——34

    "Was that the boy I sat next to in Biology?" I asked artlessly. 你是生物课坐在我旁边的男生吗?我天真烂漫的问道. & ...

  7. vertor容器

    头文件#include<vector> 1.创建vector对象 1.不指定容器大小  vector <int> v; 2.指定容器大小 vector <double&g ...

  8. webstrom 快捷键(Idea可用)

    在File-->setting可查看和配置功能快捷键,以下列出常用的快捷键 1. ctrl + shift + n: 打开工程中的文件,目的是打开当前工程下任意目录的文件. 2. ctrl + ...

  9. external 里面文件的介绍

    搞了半天android,竟然对external下的库一无所知?不能容忍! 马上解决: android-mock:编译为java静态库.说明:Android Mock is a framework fo ...

  10. Django 用户认证及OneToOneField

    Django 用户认证如果自己不想写 就可以用django自带的认证 首选导入模块 models.py #!/usr/bin/env python #_*_ coding:utf8 _*_ from ...