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.

InputThe 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.)OutputFor 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<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std; struct node
{
int l,r;
int num;
}tree[maxn<<]; struct node1
{
int pos,l,r,h;
bool friend operator <(node1 x, node1 y)
{
return x.h<y.h;
}
}h[maxn];
struct node2
{
int pos,h;
bool friend operator <(node2 x,node2 y)
{
return x.h<y.h;
}
}p[maxn]; void pushup(int m)
{
tree[m].num=(tree[m<<].num+tree[m<<|].num);
return;
}
void build(int m,int l,int r)
{
tree[m].l=l;
tree[m].r=r;
tree[m].num=;
if(l==r)
{
return ;
}
int mid=(tree[m].l+tree[m].r)>>;
build(m<<,l,mid);
build(m<<|,mid+,r);
return;
}
void update(int m,int index,int val)
{
if(tree[m].l==index&&tree[m].l==tree[m].r)
{
tree[m].num=val;
return ;
}
int mid=(tree[m].l+tree[m].r)>>;
if(index<=mid)
{
update(m<<,index,val);
}
else
{
update(m<<|,index,val);
}
pushup(m);
return ;
}
int query(int m,int l,int r)
{
if(tree[m].l==l&&tree[m].r==r)
{
return tree[m].num;
}
int mid=(tree[m].l+tree[m].r)>>;
if(r<=mid)
{
return query(m<<,l,r);
}
else if(l>mid)
{
return query(m<<|,l,r);
}
else
{
return query(m<<,l,mid)+query(m<<|,mid+,r);
}
}
int a[maxn];
int main()
{
int T;
cin>>T;
for(int k=;k<=T;k++)
{
int n,m;
scanf("%d%d",&n,&m);
for(int t=;t<=n;t++)
{
scanf("%d",&p[t].h);
p[t].pos=t;
}
for(int t=;t<=m;t++)
{
scanf("%d%d%d",&h[t].l,&h[t].r,&h[t].h);
h[t].l++;
h[t].r++;
h[t].pos=t;
} printf("Case %d:\n",k);
build(,,n);
sort(p+,p+n+);
sort(h+,h+m+);
int j=;
int s=;
while(s<=n)
{
if(p[s].h>h[j].h)
{
// cout<<h[j].l<<" "<<h[j].r<<endl;
a[h[j].pos]=query(,h[j].l,h[j].r);
j++;
if(j>m)
{
break;
}
}
else
{
update(,p[s].pos,);
s++;
}
}
while(j<=m)
{
a[h[j].pos]=query(,h[j].l,h[j].r);
j++;
}
for(int t=;t<=m;t++)
{
printf("%d\n",a[t]);
}
} return ;
}

最新文章

  1. VB中键盘每个按键所对应的具体数值是?
  2. as3 中文转拼音
  3. 【bzoj1597】 土地购买
  4. 学习笔记-动态树Link-Cut-Tree
  5. POJ3764 The xor-longest path Trie树
  6. vs运行代码版本不一致删除缓存
  7. Android群英传》读书笔记 (4) 第八章 Activity和Activity调用栈分析 + 第九章 系统信息与安全机制 + 第十章 性能优化
  8. 面向对象三大特征之继承(extends)——Java笔记(六)
  9. 记录兼容IE8中发现的一些问题
  10. 广告中的AdNetwork、AdExchange、DSP、SSP、RTB和DMP是什么?
  11. html框架练习-基本网页制作
  12. 剑指Offer——小米+小红书笔试题+知识点总结
  13. NI_NUMERICHOST&quot; is not exported by the Socket module &quot;getaddrinfo&quot; is not expo
  14. GDB调试原理——ptrace系统调用
  15. Hbase 与Hive整合
  16. 测试驱动开发 - Test-Driven Development
  17. gym 101986
  18. mysql explicit_defaults_for_timestamp 变量的作用
  19. 使用keytool生成密钥对
  20. ## 20155336 2016-2017-2《JAVA程序设计》第八周学习总结

热门文章

  1. UIPickView的简单使用
  2. QWebEngineView简单使用
  3. linux学习笔记之makefile
  4. JavaScript中为什么需要!!?
  5. C++字符串转整形、浮点型stof()、atoi()、strtol()等
  6. C#LeetCode刷题之#205-同构字符串(Isomorphic Strings)
  7. css如何让子元素在父元素中水平垂直居中
  8. 如何通过命令行简单的执行C程序
  9. kafka-clients 1.0 高阶API消费消息(未完)
  10. Oracle和Mysql分页的区别