当前位置:网站首页>Chairman tree review
Chairman tree review
2022-07-28 08:17:00 【Oops_ Corsini】
Chairman tree : Persistent weight segment tree
Templates ( Query interval No k Big , Single point modification ):luogu【 Templates 】 Persistent line tree 2
Using the idea of prefix and , Dynamic opening point
Use the existing and unchanging parts to reduce the space complexity 
#include<bits/stdc++.h>
#define ll long long
#define maxn 200010
using namespace std;
int n,m;
ll a[maxn];// Original array
ll b[maxn];// Discrete array
int tot;
struct node{
int l,r,sum;
}e[maxn*50];
int cnt,rot[maxn];// Root node array
void insert(int l,int r,int pre,int &now,int k){
e[++cnt]=e[pre];
now=cnt;
e[now].sum++;
if(l==r)return ;
int mid=(l+r)>>1;
if(k<=mid)insert(l,mid,e[pre].l,e[now].l,k);
else insert(mid+1,r,e[pre].r,e[now].r,k);
}
int query(int l,int r,int L,int R,int k){
if(l==r){
return l;
}
int mid=(l+r)>>1;
int res=e[e[R].l].sum-e[e[L].l].sum;
if(k<=res)return query(l,mid,e[L].l,e[R].l,k);
else return query(mid+1,r,e[L].r,e[R].r,k-res);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
b[i]=a[i];
}
sort(b+1,b+n+1);
tot=unique(b+1,b+n+1)-b-1;
for(int i=1;i<=n;i++){
int k=lower_bound(b+1,b+tot+1,a[i])-b;
insert(1,n,rot[i-1],rot[i],k);
}
for(int L,R,k,i=1;i<=m;i++){
scanf("%d%d%d",&L,&R,&k);
cout<<b[query(1,n,rot[L-1],rot[R],k)]<<endl;
}
return 0;
}
边栏推荐
- Parse tree structure JS
- Change the dataDir path after mysql8.0.16 installation
- Yaml parameter configuration based on singleton mode
- What if the computer folder cannot be renamed?
- 聊一聊数据库的行存与列存
- Flowable workflow all business concepts
- ArcGIS JS customizes the accessor and uses the watchutils related method to view the attribute
- “蔚来杯“2022牛客暑期多校训练营2补题记录(DGHJKL)
- 对spark算子aggregateByKey的理解
- 03 | project deployment: how to quickly deploy a website developed based on the laravel framework
猜你喜欢

Oracle local network service

ASP. Net core technology insider and project practice after reading

Lecture notes a utility for everyone to generate PCG

YOLO系列损失函数详解

MPLS --- 多协议标签交换技术

谈谈DOM0,DOM1,DOM2,DOM3

解决CNN固有缺陷!通用 CNN 架构CCNN来了| ICML2022

Some experience of gd32 using Hal Library of ST and Gd official library

XMPP Service Research (II) prosody create account

Record a MYCAT connection and solve the problems of communications link failure
随机推荐
Digital management insight into retail and e-commerce operations -- Introduction to digital management
ArcGIS JS customizes the accessor and uses the watchutils related method to view the attribute
【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题
Swm32 series tutorial 5-adc application
2022/7/27 examination summary
快速搭建DMHS DM之间双向同步
MySQL basic knowledge learning (II)
Enum class
SWM32系列教程5-ADC应用
Lecture notes a utility for everyone to generate PCG
Elaborate on common mode interference and differential mode interference
基于单例模式的yaml参数配置
js卡片层叠样式的图片切换js特效
How to understand the adjective prefix of socket: "connection oriented" and "connectionless"
Chapter 01 introduction of [notes of Huashu]
Autodesk desktop licensing service error 1067 handling method
[dry goods] 32 EMC standard circuits are shared!
C language explanation series - array explanation, one-dimensional array, two-dimensional array
node(一)
EMC's "don't come back until you rectify"