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

这个题和上个题差不多…
但是有不少需要以后写主席树注意的事情
第一个是查询的时候注意lowerbound的问题
它会返回第一个不比他小的
upperbound返回第一个比他大的
记住….

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<memory.h>
using namespace std;
int shuru[100001],tu[100001],zuo[2000001],you[2000001],su[2000001],shu[100001],tou;
int gengxin(int shangyike,int weizhi,int zo,int yo)
{int xianzai=++tou;if(zo==yo){su[xianzai]=su[shangyike]+1;return xianzai;}int mid=(zo+yo)/2;if (weizhi <= mid){you[xianzai] = you[shangyike];zuo[xianzai] = gengxin(zuo[shangyike], weizhi, zo, mid);}else{you[xianzai] = gengxin(you[shangyike], weizhi, mid + 1, yo);zuo[xianzai] = zuo[shangyike];}su[xianzai] = su[zuo[xianzai]] + su[you[xianzai]];return xianzai;
}
int wen(int qian, int hou, int zo, int yo, int k)
{if(yo<=k)return su[hou]-su[qian];else if(zo>k)return 0;else{int mid=(zo+yo)/2;int zoz=wen(zuo[qian],zuo[hou],zo,mid,k);int yoy=wen(you[qian],you[hou],mid+1,yo,k);return zoz+yoy;}
}
int main()
{int T;int u=0;cin>>T;while(T--){tou=0;memset(tu,0,sizeof(tu));memset(zuo,0,sizeof(zuo));memset(you,0,sizeof(you));memset(su,0,sizeof(su));memset(shu,0,sizeof(shu));int n,m;cin>>n>>m;for(int a=1;a<=n;a++){scanf("%d",&shuru[a]);tu[a]=shuru[a];}sort(tu+1,tu+n+1);printf("Case %d:\n",++u);int lisa=unique(tu+1,tu+n+1)-tu-1;//shu[0]=jianli(1,lisa);int q,w,e;for(int a=1;a<=n;a++){int weizhi=lower_bound(tu+1,tu+lisa+1,shuru[a])-tu;shu[a]=gengxin(shu[a-1],weizhi,1,lisa);}while (m--){int q, w, e;cin >> q >> w >> e;q++,w++;e=upper_bound(tu+1,tu+lisa+1,e)-tu-1;cout << wen(shu[q-1], shu[w], 1, lisa, e) << endl;}}return 0;
}

HDU4417 主席树入门2相关推荐

  1. poj2104 k-th number 主席树入门讲解

    poj2104 k-th number 主席树入门讲解 定义:主席树是一种可持久化的线段树 又叫函数式线段树   刚开始学是不是觉得很蒙逼啊 其实我也是 主席树说简单了 就是 保留你每一步操作完成之后 ...

  2. 【模板】可持久化线段树 1(主席树)

    题目背景 这是个非常经典的主席树入门题--静态区间第K小 数据已经过加强,请使用主席树.同时请注意常数优化 题目描述 如题,给定N个正整数构成的序列,将对于指定的闭区间查询其区间内的第K小值. 输入输 ...

  3. 【用学校抄作业带你走进可持久化线段树(主席树)】可持久化线段树概念+全套模板+例题入门:[福利]可持久化线段树)

    我似乎很少写这种算法博客 可持久化线段树概念 概念介绍(类比帮助理解) 简单分析一下时间和空间复杂度(内容池) 模板 结构体变量 建树模板 单点修改模板 单点查询模板 区间修改模板(pushup) 区 ...

  4. 线段树简单入门 (含普通线段树, zkw线段树, 主席树)

    线段树简单入门 递归版线段树 线段树的定义 线段树, 顾名思义, 就是每个节点表示一个区间. 线段树通常维护一些区间的值, 例如区间和. 比如, 上图 \([2, 5]\) 区间的和, 为以下区间的和 ...

  5. 【代码源 Div1 - 108】#464. 数数(主席树,区间比k小的数的个数)HDU4417

    problem solution 主席树查询区间比k小的数的个数 建树之后直接在目标区间的主席树内将 H 作为挡板递归计数. #include<bits/stdc++.h> using n ...

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

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

  7. HDU4417 Super Mario (主席树模板)

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

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

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

  9. NOI数据结构:主席树

    主席树详解 主席树详解_西红柿爱炒番茄-CSDN博客 最详细的主席树(不修改,待修改) BZOJ 1901 最详细的主席树(不修改,待修改) BZOJ 1901_Bartholomew_的博客-CSD ...

最新文章

  1. Oracle迁移至PostgreSQL工具之Ora2Pg
  2. 第三篇——第二部分——第六文 监控SQL Server镜像
  3. array_reduce() 与 array_map()
  4. java 参数 string_java(String和StringBuffer分别作为参数传递)
  5. 关于去苹果服务器验证充值的一些看法
  6. Genome Research封面文章|张勇课题组开发方法绘制胚胎发育早期转录因子结合位点图谱...
  7. PNG免扣苹果IPHONE手机模型样机,让一切简单一点!
  8. c语言disp是什么意思及用法,disp(disp是什么功能)
  9. python 模块 类 函数_Python17之函数、类、模块、包、库
  10. 自学Java的人,如何系统全面的学习?
  11. mfc编程淘汰了吗_四种基本的编程命名规范(匈牙利命名法、驼峰式命名法、帕斯卡命名法、下划线命名法)...
  12. 计算机网络的非性能特征PPT,计算机网络概述课件课件.ppt
  13. Python 爬虫 ——html 页面的认识
  14. android自定义手势解锁View
  15. java线程同步机制,实现同步锁
  16. Java五子棋全代码
  17. matlab中figure的基本用法
  18. NMI(Normalized Mutual Information)
  19. python告诉你ti8 dota2英雄bp
  20. 程序员常用工具网站汇总(一)

热门文章

  1. 手机banner图片自适应手机宽高定位
  2. 【大牛系列教学】如何准备面试?
  3. Java 多态的薪酬计算的练习
  4. 如何更改工程内最少的代码修改系统UISwitch的大小和样式
  5. Redis11_缓存穿透和雪崩
  6. 网站的养站(养蜘蛛)技巧
  7. 理想汽车IPO,与特斯拉之间还差了20个蔚来
  8. 创业团队:太极图形团队
  9. Homework 1 : Knowledge items of C++ Answer (part 1)
  10. TADF材料的机制原理;TADF的机理;热活化延迟荧光如何产生?