Super Mario

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6174    Accepted Submission(s): 2675

Problem 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
 
 
Source
 题意:给你n个数 m个查询 l r x  问区间[l,r]中小于等于x的数的个数
 题解:离线+树状数组 将n个数的的位置存入树状数组。
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
int t;
int n,m;
int tree[];
int ans[];
int lowbit(int tt)
{
return tt&(-tt);
}
void add(int x,int y)
{
for(int i=x; i<=n; i+=lowbit(i))
tree[i]+=y;
}
int getsum(int x)
{
int ans=;
for(int i=x; i>; i-=lowbit(i))
ans+=tree[i];
return ans;
}
struct node
{
int w;
int pos;
} N[];
struct xx
{
int l,r;
int x;
int pos;
} M[];
bool cmp1 (struct node aa,struct node bb)
{
return aa.w<bb.w;
}
bool cmp2 (struct xx aa,struct xx bb)
{
return aa.x<bb.x;
}
int main()
{
scanf("%d",&t);
for(int i=; i<=t; i++)
{
memset(tree,,sizeof(tree));
scanf("%d %d",&n,&m);
for(int j=; j<=n; j++)
{
scanf("%d",&N[j].w);
N[j].pos=j;
}
sort(N+,N++n,cmp1);
for(int j=; j<=m; j++)
{
scanf("%d %d %d",&M[j].l,&M[j].r,&M[j].x);
M[j].l++;
M[j].r++;
M[j].pos=j;
}
sort(M+,M++m,cmp2);
int exm=;
for(int j=; j<=m; j++)
{
while(exm<=n&&N[exm].w<=M[j].x)
{
add(N[exm].pos,);
exm++;
}
ans[M[j].pos]=getsum(M[j].r)-getsum(M[j].l-);
}
printf("Case %d:\n",i);
for(int j=; j<=m; j++)
printf("%d\n",ans[j]);
}
return ;
}

HDU 4417 离线+树状数组的更多相关文章

  1. 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组

    题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...

  2. 区间的关系的计数 HDU 4638 离线+树状数组

    题目大意:给你n个人,每个人都有一个id,有m个询问,每次询问一个区间[l,r],问该区间内部有多少的id是连续的(单独的也算是一个) 思路:做了那么多离线+树状数组的题目,感觉这种东西就是一个模板了 ...

  3. HDU - 4777 离线树状数组

    离线树状数组搞一搞. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #de ...

  4. 区间gcd问题 HDU 5869 离线+树状数组

    题目大意:长度n的序列, m个询问区间[L, R], 问区间内的所有子段的不同GCD值有多少种. 子段就是表示是要连续的a[] 思路:固定右端点,预处理出所有的gcd,每次都和i-1的gcd比较,然后 ...

  5. HDU 5249 离线树状数组求第k大+离散化

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

  6. HDU 5869 (离线+树状数组)

    Problem Different GCD Subarray Query 题目大意 给定n个数的序列,有q个询问,每次询问一个区间中所有子区间所形成不同的gcd的数量. 解题分析 由于固定一个数为右端 ...

  7. hdu 4605 Magic Ball Game (在线主席树/离线树状数组)

    版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4605 题意: 有一颗树,根节点为1,每一个节点要么有两个子节点,要么没有,每个节点都有一个权值wi .然后,有一个球,附带值x . 球 ...

  8. HDU 2852 KiKi's K-Number(离线+树状数组)

    题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...

  9. POJ 3416 Crossing --离线+树状数组

    题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...

随机推荐

  1. JVM--内存模型与线程

    一.硬件与效率的一致性 计算机的存储设备与处理器的运算速度存在几个数量级的差距,现在计算机系统不得不在内存和处理器之间增加一层高速缓存(cache)来作为缓冲.将运算需要的数据复制到缓存中,让运算能够 ...

  2. 372. Delete Node in a Linked List【LintCode java】

    Description Implement an algorithm to delete a node in the middle of a singly linked list, given onl ...

  3. [leetcode-666-Path Sum IV]

    If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...

  4. BZOJ 3790 神奇项链 hash/后缀自动机+贪心

    Description 母亲节就要到了,小 H 准备送给她一个特殊的项链.这个项链可以看作一个用小写字母组成的字符串,每个小写字母表示一种颜色. 为了制作这个项链,小 H 购买了两个机器.第一个机器可 ...

  5. SPOJ 8073 The area of the union of circles(计算几何の圆并)(CIRU)

    Description You are given N circles and expected to calculate the area of the union of the circles ! ...

  6. Mishka and Contest(模拟水题)

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...

  7. eg_1

    1. 编写一个程序,输出一个字符串中的大写英文字母个数,小写英文字母个数以及非英文字母个数. 第一种方法: public class Test { public static void main(St ...

  8. ACM 第十四天

    字符串: 1.KMP算法(模式串达到1e6) 模式串达到1e4直接暴力即可. 字符串哈希 字符串Hash的种类还是有很多种的,不过在信息学竞赛中只会用到一种名为“BKDR Hash”的字符串Hash算 ...

  9. ios::sync_with_stdio(false)提高C++读写速度

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:ios::sync_with_stdio(false)提高C++读写速度     本文地址:h ...

  10. WebService部署服务器调试时提示 “测试窗体只能用于来自本地计算机的请求”解决方法

    原因:没有开启服务器访问权限! 解决方法: 在web.config的<system.web></system.web>中加入如下配置节内容即可解决 <webService ...