日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

HDU-4417 Super Mario

發(fā)布時(shí)間:2024/4/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU-4417 Super Mario 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Super Mario

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

?題意:求區(qū)間[l-r]的<=k的個(gè)數(shù)

裸的主席樹,離散化一下就行了。

#include<bits/stdc++.h> using namespace std; #define Debug(x) cout<<#x<<":"<<(x)<<endl typedef long long ll; const int maxn = 100000+5; struct node {int l,r,num; }tree[maxn*20]; int a[maxn],b[maxn],rt[maxn],cnt; void pushup(int k) {tree[k].num=tree[tree[k].l].num+tree[tree[k].r].num; } void build(int l,int r,int &x) {x=++cnt;tree[x].num=0;if(l==r) return ;int m=(l+r)>>1;build(l,m,tree[x].l);build(m+1,r,tree[x].r);pushup(x); } int query(int l,int r,int pre,int now,int x,int y) {if(x<=l&&r<=y) return tree[now].num-tree[pre].num;int m=(l+r)>>1;int ans=0;if(x<=m) ans+=query(l,m,tree[pre].l,tree[now].l,x,y);if(y>m) ans+=query(m+1,r,tree[pre].r,tree[now].r,x,y);return ans; } void updata(int l,int r,int pre,int &now,int k) {now=++cnt;tree[now]=tree[pre];if(l==r){tree[now].num++;return ;}int m=(l+r)>>1;if(k<=m) updata(l,m,tree[pre].l,tree[now].l,k);else updata(m+1,r,tree[pre].r,tree[now].r,k);pushup(now); } int main() {int n,m,t,p=1;scanf("%d",&t);while(t--){printf("Case %d:\n",p++);scanf("%d %d",&n,&m);{cnt=0;for(int i=1; i<=n; i++)scanf("%d",&a[i]),b[i]=a[i];sort(b+1,b+1+n);int len=unique(b+1,b+1+n)-(b+1);for(int i=1; i<=n; i++)a[i]=lower_bound(b+1,b+1+len,a[i])-b;build(1,len,rt[0]);for(int i=1; i<=n; i++)updata(1,len,rt[i-1],rt[i],a[i]);while(m--){int l,r,k1,k;scanf("%d %d %d",&l,&r,&k);l++;r++;k1=lower_bound(b+1,b+1+len,k)-b;if(b[k1]!=k) k1--;if(k1==0)//不判斷會(huì)出現(xiàn)MLE {printf("0\n");continue;}printf("%d\n",query(1,len,rt[l-1],rt[r],1,k1));}}} }

?

?

?

PS:摸魚怪的博客分享,歡迎感謝各路大牛的指點(diǎn)~

轉(zhuǎn)載于:https://www.cnblogs.com/MengX/p/9104963.html

總結(jié)

以上是生活随笔為你收集整理的HDU-4417 Super Mario的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。