hdu4417 Super Mario
来源:互联网 发布:2178手游充值库存软件 编辑:程序博客网 时间:2024/06/10 22:09
Super Mario
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1575 Accepted Submission(s): 760
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.)
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
110 100 5 2 7 5 4 3 8 7 7 2 8 63 5 01 3 11 9 40 1 03 5 55 5 14 6 31 5 75 7 3
Sample Output
Case 1:4003120151
Source
2012 ACM/ICPC Asia Regional Hangzhou Online
简单的线段树
#include <iostream>#include <stdio.h>#include <algorithm>#define MAXN 100500using namespace std;struct node { int x,id; bool operator <(node b)const{return x<b.x;}}no[MAXN];struct que{ int l,r,h,id; bool operator <(que b)const{return h<b.h;}}qu[MAXN];int l[MAXN*20],ans[MAXN];bool cmp1(node a,node b){return a<b;}bool cmp2(que a,que b){return a<b;}void build(int num,int s,int e){ l[num]=0; if(s>=e) return ; int mid=(s+e)>>1; build(num<<1,s,mid); build(num<<1|1,mid+1,e);}int update(int num,int s,int e,int a){ if(s>=e) { l[num]++; return 1; } int mid; mid=(s+e)>>1; if(a<=mid)update(num<<1,s,mid,a); else if(a>mid)update(num<<1|1,mid+1,e,a); l[num]=l[num<<1]+l[num<<1|1];}int query(int num,int s,int e,int a,int b){ if(a<=s&&b>=e) { return l[num]; } int mid=(s+e)>>1,re=0; if(a<=mid)re+=query(num<<1,s,mid,a,b); if(b>mid)re+=query(num<<1|1,mid+1,e,a,b); return re;}int main(){ int n,m,tcase,i,j,t=1,tempa,tempb; scanf("%d",&tcase); while(tcase--) { scanf("%d%d",&n,&m); build(1,1,n); for(i=1;i<=n;i++) { scanf("%d",&no[i].x); no[i].id=i; } sort(no+1,no+1+n,cmp1); for(i=1;i<=m;i++) { scanf("%d%d%d",&tempa,&tempb,&qu[i].h); qu[i].l=tempa+1; qu[i].r=tempb+1;qu[i].id=i; } sort(qu+1,qu+1+m,cmp2); for(j=1,i=1;j<=m;j++) { while(i<=n&&no[i].x<=qu[j].h) { update(1,1,n,no[i].id); i++; } ans[qu[j].id]=query(1,1,n,qu[j].l,qu[j].r); } printf("Case %d:\n",t++); for(i=1;i<=m;i++) printf("%d\n",ans[i]); } return 0;}
- HDU4417 Super Mario
- hdu4417 Super Mario
- HDU4417-Super Mario
- hdu4417 Super Mario
- hdu4417 Super Mario
- HDU4417-Super Mario
- hdu4417 Super Mario
- hdu4417 Super Mario
- HDU4417 Super Mario(树状数组)
- HDU4417 Super Mario【树状数组】
- Super Mario(hdu4417,树状数组)
- hdu4417 Super Mario 线段树端点更新
- hdu4417 Super Mario (主席树+二分)
- hdu4417 Super Mario (主席树入门)
- HDU4417 Super Mario 线段树离线操作
- hdu4417- Super Mario(离线,线段树)
- 主席树总结-hdu4417 Super Mario
- HDU4417 Super Mario(划分树+二分)
- hdu4414 Finding crosses
- [二次开发]dede会员列表调用(企业、个人)
- 9.3 折半查找
- clip:rect('top', 'right', 'bottom', 'left')
- Jackson多态类型数据的反序列化
- hdu4417 Super Mario
- QT 多页面切换之QTabWidget
- 20130827组队赛Regionals 2012, North America - Greater NY
- 使用C/C++扩展Python zz
- 图像二值化算法
- 大把免费编程书籍
- hdu4463 Outlets
- linux 客户端 Socket 非阻塞connect编程
- 技术网址