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. javaee Listener

    Servlet API 中定义了几种监听器,大多数尽管不是全部,都将监听某种形式的会话活动,通过实现对应事件的监听器接口订阅某个事件,然后在部署描述符中添加 <listener> 配置,或 ...

  2. usdt信息小结

    https://blog.csdn.net/weixin_42208011/article/details/80499536 https://blog.csdn.net/weixin_42208011 ...

  3. 家用甲醛pm2.5温湿度传感器实验

    最近在装修房子,刷完墙漆铺完了木地板以后,屋里边有很大的味,所以就买了 攀藤科技的PMS5003ST G5ST PM2.5激光粉尘甲醛温湿度三合一传感器,打算自己测一下甲醛浓度,看看什么时候能够入住. ...

  4. 转:Linux 编译安装 Mysql5.7

    http://broqiang.com/2017/04/18/Mysql-Install-5.7.18-Linux-Compile/ 原文 Linux 编译安装 Mysql5.7 Ubuntu 下快速 ...

  5. Notes of the scrum meeting before publishing2(12.18)

    meeting time:18:30~20:30p.m.,December 18th,2013 meeting place:3号公寓一层 attendees: 顾育豪                  ...

  6. Java实验二实验报告:java面向对象程序设计

    java实验二实验报告 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 实验 ...

  7. java---StringBuilder类的用法(转载)

    转载自http://blog.csdn.net/zi_jun/article/details/7624999 String对象是不可改变的.每次使用 System.String类中的方法之一时,都要在 ...

  8. ACM 第十七天

    暑期热身赛 BAPC 2014 The 2014 Benelux Algorithm Programming Contest 题目网址:https://odzkskevi.qnssl.com/3655 ...

  9. LintCode-379.将数组重新排序以构造最小值

    将数组重新排序以构造最小值 给定一个整数数组,请将其重新排序,以构造最小值. 注意事项 The result may be very large, so you need to return a st ...

  10. 《学习OpenCV》课后习题解答3

    题目:(P104) 创建一个大小为100*100的三通道RGB图像.将它的元素全部置0.使用指针算法以(20,5)与(40,20)为项点绘制一个绿色平面. 解答: #include "cv. ...