Super Mario

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8654    Accepted Submission(s): 3646

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

提示:向左搜就搜到底,向右搜就将左树加上。

/*
题意:求区间中小于等于H的数思路:主席树模板,修改query即可*/#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+10;
int cnt,ans;
int a[maxn],root[maxn];
vector<int> v;struct node{int l,r,sum;
}T[maxn*25];int getid(int x){return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
} int getansid(int x){return upper_bound(v.begin(),v.end(),x)-v.begin();
} void update(int l,int r,int &x,int y,int pos){T[++cnt]=T[y];T[cnt].sum++;x=cnt;if(l==r) return;int mid=(l+r)>>1;if(mid >= pos) update(l,mid,T[x].l,T[y].l,pos);else update(mid+1,r,T[x].r,T[y].r,pos);
}int query(int l,int r,int x,int y,int val){if(l==r) return T[y].sum-T[x].sum;            //查询成功 int mid = (l+r)>>1;    int res=0;    if(mid >= val ){res=query(l,mid,T[x].l,T[y].l,val);}else{res+=T[T[y].l].sum-T[T[x].l].sum;res+=query(mid+1,r,T[x].r,T[y].r,val);}return res;
}int main(){int t,n,m,l,r,p;scanf("%d",&t);for(int k=1;k<=t;k++){cnt=0;v.clear();scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%d",&a[i]);v.push_back(a[i]);    }sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());for(int i=1;i<=n;i++) update(1,n,root[i],root[i-1],getid(a[i]));printf("Case %d:\n",k);for(int i=0;i<m;i++){scanf("%d%d%d",&l,&r,&p);if(getansid(p)==0) printf("0\n");else printf("%d\n",query(1,n,root[l],root[r+1],getansid(p)));}}
} 

HDU4417 Super Mario (主席树模板)相关推荐

  1. HDU-4417 Super Mario (主席树)

    Mario is world-famous plumber. His "burly" figure and amazing jumping ability reminded in ...

  2. HDU4417 Super Mario 主席树

    欢迎访问~原文出处--博客园-zhouzhendong 去博客园看该题解 题目传送门 - HDU4417 题意概括 给定一个长度为n的区间,同时给出m个询问,每次询问在区间[l,r]中有多少个数小于或 ...

  3. HDU4417 Super Mario(离线树状数组或者主席树+二分)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. #HDU 4417 Super Mario (主席树 + 二分)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. HDU - 4417 Super Mario(主席树/线段树+离线)

    题目链接:点击查看 题目大意:给出由 n 个数的数列,再给出 m 次查询,每次查询需要输出 [ l , r ] 内小于等于 h 的数有多少个 题目分析:大晚上睡不着觉随便做做题,发现这个题目原来可以用 ...

  6. hdu4417 Super Mario(树状数组+离线区间操作)

    题目链接 Problem Description Mario is world-famous plumber. His "burly" figure and amazing jum ...

  7. [HDU4417]Super Mario

    [HDU4417]Super Mario Mario is world-famous plumber. His "burly" figure and amazing jumping ...

  8. HDU 4417 Super Mario(线段树离线处理/主席树)

    Mario is world-famous plumber. His "burly" figure and amazing jumping ability reminded in ...

  9. HDU-4417 Super Mario

    Super Mario Mario is world-famous plumber. His "burly" figure and amazing jumping ability ...

最新文章

  1. 面向对象方法综述(工具<方法<思维<价值观)
  2. Expression Web 3 安装问题
  3. centos7 系统缓存清理
  4. 基于Proxy思想的Android插件框架
  5. 禁止sethc.exe运行 防止3389的sethc后门
  6. Windows下 Python3.7.0 运行环境的搭建 一套操作后就可以使用Python写代码啦~
  7. 升级到Oracle 19c:你不可不知的十大SQL问题(上)
  8. Java学习资源、视频教程汇总
  9. 集群、分布式、集中式、伪分布式的概念与区别
  10. 大数据平台有什么功能
  11. 跨页面实现多选(转)
  12. 一道打印菱形的面试题
  13. 用粉红噪声煲机_解析什么是白噪和粉噪?耳机煲机用白噪好还是粉噪
  14. oracle插入获取当前时间,Oracle中如何获取系统当前时间
  15. 一步一步实现一个简单的OS(先小装一下)
  16. H3C防火墙-安全域
  17. 基于无人机倾斜摄影和深度学习算法的单树点云分割方法研究
  18. 【ADRC】扩张状态观测器(ESO)
  19. 提高生产力和效率的小方法
  20. 低通滤波器转带通滤波器公式由来_射频/微波滤波器

热门文章

  1. UCOSiii难疑之——“OS_SAFETY_CRITICAL”
  2. Excel对多个工作表批量分解导出为独立工作簿
  3. 12个高矮不同的人,排成两排,每排必须是从矮到高排列,而且第二排比对应的第一排的人高,问排列方式有多少种?
  4. 剑指offer第7题 重建二叉树
  5. slq clause
  6. iOS 苹果企业账号申请流程,流水式申请步骤
  7. KMP 模板题 及next数组
  8. jquery 如何判断图片已经加载完成
  9. ElasticSearch 6.3.2版本使用 ik + 拼音复合分词 搜索
  10. DTMF拨号音识别手机键盘密码 —— 【WUST-CTF2020】girlfriend