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 ;
}

最新文章

  1. 1032: [JSOI2007]祖码Zuma
  2. TCP的那些事儿(下)
  3. DedeCMS生成首页html静态文件的教程
  4. Python入门-多行语句
  5. ScannerTest-------double string
  6. poj -2975 Nim
  7. 在Visual Studio中使用GitHub(使用篇)
  8. windbg命令学习2
  9. 用php(session)实现留言板功能----2017-05-09
  10. 使用jquery的方法和技巧2,点击多选框的jquery响应
  11. dedecms的include文件夹是干什么的?
  12. python基础之从认识python到python的使用
  13. .net 读写xml
  14. The &lt;classpath&gt; or &lt;modulepath&gt; for &lt;junit&gt; must include junit.jar if not in Ant&#39;s own classpath
  15. (.DS_Store)避免多人提交代码到GitHub上起冲突
  16. codevs 3022 西天收费站
  17. JUnit4测试方法异常抛出实例
  18. [分布式系统学习]阅读笔记 Distributed systems for fun and profit 抽象 之二
  19. Cocos2d-x添加Android手机震动
  20. CTF西湖论剑

热门文章

  1. 骰子涂色 (Cube painting,UVa 253)
  2. CSP201509-2:日期计算
  3. Windows环境下使用kafka单机模式
  4. 在页面使用echarts的地图(解决地图不完整)
  5. 开源自动驾驶仿真平台 AirSim (2) - 编译 AirSim
  6. 统计学习三:1.k近邻法
  7. Python3 Tkinter-Place
  8. Redis 错误摘记篇
  9. Alpha发布——视频展示
  10. 2017-2018-2 20172323 『Java程序设计』课程 结对编程练习_四则运算