博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu-4417 Super Mario(树状数组 + 划分树)
阅读量:5268 次
发布时间:2019-06-14

本文共 2276 字,大约阅读时间需要 7 分钟。

题目链接:

Time Limit: 2000/1000 MS (Java/Others)   

 Memory Limit: 32768/32768 K (Java/Others)

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
 
题意:
 
给定一个数列.给区间[l,r]问此区间内<=k的数目是多少;
 
 
思路:
 
可以用树状数组离线处理,把原序列按从小到大排序,询问也按k的大小排序,然后一边询问一边update;最近学了划分树,也可以做这题,看明天有时间想一想怎么做吧;
 
AC代码:
 
/*树状数组的代码:    4417    202MS    3744K    1873 B    G++    2014300227*/#include 
using namespace std;const int N=1e5+4;int a[N],n,m,sum[N],ans[N];struct node{ friend bool operator< (node x,node y) { if(x.num == y.num)return x.pos < y.pos; return x.num < y.num; } int l,r,pos,num;};node po[N];struct nod{ friend bool operator< (nod x,nod y) { if(x.a==y.a)return x.pos
0) { s+=sum[x]; x-=lowbit(x); } return s;}int main(){ int t; scanf("%d",&t); int cnt=1; while(t--) { memset(sum,0,sizeof(sum)); printf("Case %d:\n",cnt++); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&p[i].a); p[i].pos=i; } sort(p+1,p+n+1); for(int i=0;i

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5357496.html

你可能感兴趣的文章
4.6上午
查看>>
linux之sort用法
查看>>
Teamcenter10 step-by-step installation in Linux env-Oracle Server Patch
查看>>
Redis-jedis模拟多线程购票
查看>>
聊一聊 Flex 中的 flex-grow、flex-shrink、flex-basis
查看>>
Gcc 安装过程中部分配置
查看>>
Logparser介绍
查看>>
Js实现客户端表单的验证
查看>>
python使用input()来接受字符串时一直报错“xxx is not defined”
查看>>
哈啊哈
查看>>
vue-router在ie9及以下history模式支持
查看>>
linux基础命令--lsof
查看>>
Mysql limit
查看>>
加解密与数据校验
查看>>
stm8s_IAP_xmode串口升级
查看>>
usb 编程知识 总结
查看>>
Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
查看>>
Java基础知识强化之集合框架笔记21:数据结构之 数组 和 链表
查看>>
转:queue
查看>>
[JSOI2016] 最佳团队 (树形DP+01分数规划)
查看>>