hdu 4417 Super Mario(可持久化线段树)
题意:给你一些数,有多次询问,问你在l,r区间内小于k的数有多少个
思路:主席树大发好,虽然树状数组和线段树离线也可以做
代码:
#include <set> #include <map> #include <queue> #include <stack> #include <math.h> #include <vector> #include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #define zero(a) fabs(a)<eps #define max( x, y ) ( ((x) > (y)) ? (x) : (y) ) #define min( x, y ) ( ((x) < (y)) ? (x) : (y) ) #define lowbit(x) (x&(-x)) #define debug(a) cerr<<#a<<"=="<<a<<endl typedef long long LL; const double pi=acos(-1.0); const double eps=1e-8; const int inf=0x3f3f3f3f; const LL linf=0x3f3f3f3f3f3f3f3f; using namespace std;const int maxn=100007; int n,m,a[maxn],root[maxn],cnt,x,y,k; struct node {int l,r,sum; }T[maxn*40]; vector<int>v; int getid(int x) {return lower_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(pos<=mid)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 L,int R) {if(L>R) return 0;if(L<=l && r<=R){return T[y].sum-T[x].sum;}int mid=(l+r)>>1,ans=0;if(L<=mid) ans+=query(l,mid,T[x].l,T[y].l,L,R);if(R>mid) ans+=query(mid+1,r,T[x].r,T[y].r,L,R);return ans; } int main() {int tt;scanf("%d",&tt);int cas=1;while(tt--){scanf("%d%d",&n,&m);v.clear();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(0,v.size()-1,root[i],root[i-1],getid(a[i]));}printf("Case %d:\n",cas++);int t1,t2,t3;while(m--){scanf("%d%d%d",&t1,&t2,&t3);int pos=upper_bound(v.begin(),v.end(),t3)-v.begin()-1;printf("%d\n",query(0,v.size()-1,root[t1],root[t2+1],0,pos));}}return 0; }
转载于:https://www.cnblogs.com/lalalatianlalu/p/8855114.html
hdu 4417 Super Mario(可持久化线段树)相关推荐
- HDU 4417 Super Mario(莫队 + 树状数组 + 离散化)
Super Mario 思路 区间查找问题,容易想到离线莫队,确实这题就是莫队,接下来我们考虑如何维护区间高度值问题. 既然是离线嘛,我们容易想到离散化和他挂钩,想想这题是否需要离散化,高度的最大值是 ...
- HDU 4417 Super Mario(线段树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU - 4417 Super Mario(主席树/线段树+离线)
题目链接:点击查看 题目大意:给出由 n 个数的数列,再给出 m 次查询,每次查询需要输出 [ l , r ] 内小于等于 h 的数有多少个 题目分析:大晚上睡不着觉随便做做题,发现这个题目原来可以用 ...
- HDU 4417 Super Mario(线段树离线处理/主席树)
Mario is world-famous plumber. His "burly" figure and amazing jumping ability reminded in ...
- HDU 4417 Super Mario(线段树||树状数组+离线操作 之线段树篇)
Mario is world-famous plumber. His "burly" figure and amazing jumping ability reminded in ...
- HDU 4417 Super Mario(离线线段树or树状数组)
Problem Description Mario is world-famous plumber. His "burly" figure and amazing jumping ...
- hdu 4417 Super Mario 树状数组||主席树
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- HDU 4417 Super Mario(划分树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- #HDU 4417 Super Mario (主席树 + 二分)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
最新文章
- java 行为模式_java设计模式--行为模式
- 【数据结构作业心得】4-0 二叉树
- ubuntu安装curl报错或get update失败
- Visifire Silverlight Charts (基于SilverLight的Chart组件)
- 问答机器人接口python_设计用于机器学习工程的Python接口
- 浅谈OpenCL之Platform API(2)
- ArcGIS支持的常用数据类型
- linux命令大全(持续更新)
- 【服务器】创建docker、运行jupyter相关命令
- 关于idea中运行maven项目报错显示找不到包或符号的问题——终极方案
- SCRT804安装教程
- Linux 创建并且运行Django项目
- DXP2004/Altium Desinger 自己画元器件和封装,及注意事项
- html qq在线状态,qq各种在线状态意思
- 2018 Google 开发者大会.md
- HIGEN海坚驱动器维修FDA7045伺服变频器维修
- android webview 加载过程,实战:七步完成Android Webview图片加载
- linux usb回环程序,在Linux中创建回环设备(loopback device)的方法
- 目前主流微型计算机显卡总线接口是,江苏省2011年普通高校对口单招文化统考计算机专业综合理论试卷B...
- split().reverse().join()放一起 好记很多
热门文章
- 摘自ubantuer-Linux防火墙iptables学习笔记(三)iptables命令详解和举例
- Maven系列三Maven内置变量
- java_ant详解
- asp.net中page对象生命周期和各事件执行顺序
- 79. Word Search
- Linux常用命令行
- 牛客网 2018年全国多校算法寒假训练营练习比赛(第三场)D.小牛vs小客-博弈
- 使3D空间中物体朝向和其速度方向一致的旋转矩阵计算方案
- public void DeleteT(ListT EntityList) where T : class, new() 这是什么意思
- CentOS 6.0图解网络安装全过程