洛谷 P3369:[模板] 普通平衡树 ← Splay树

平衡树【Splay树】学习小记 平衡树,顾名思义,平衡的搜索二叉树。常见的平衡树都能将树的深度保持在lg⁡n\lg_nlgn​的级别内,防止退化成链。一些平衡树可以通过旋转、分裂、合并等操作完成更加高级的、二叉搜索树做不到的操作。 阅读详情

【题目来源】
https://www.luogu.com.cn/problem/P3369

【题目描述】
您需要动态地维护一个可重集合 M,并且提供以下操作:
(1)向 M 中插入一个数 x。
(2)从 M 中删除一个数 x。(若有多个相同的数,应只删除一个)
(3)查询 M 中有多少个数比 x 小,并且将得到的答案加 1。
(4)查询如果将 M 从小到大排列后,排名位于第 x 位的数。
(5)查询 M 中 x 的前驱(定义为 M 中小于 x,且最大的数)。
(6)查询 M 中 x 的后继(定义为 M 中大于 x,且最小的数)。
对于操作 3,5,6,不保证当前可重集中存在数 x。
对于操作 4,5,6,保证答案一定存在。

【输入格式】
第一行为 n,表示操作的个数,下面 n 行每行有两个数 opt 和 x,opt 表示操作的序号(1≤opt≤6)。​​​​​​​

【输出格式】
对于操作 3,4,5,6 每行输出一个数,表示对应答案。​​​​​​​

【输入样例】
10
1 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598​​​​​​​

【输出样例】
106465
84185
492737​​​​​​​

【数据范围】
对于 100% 的数据,1≤n≤10^5,∣x∣≤10^7。

【算法分析】
● Treap 树解决平衡的办法是给每个结点加上一个随机的优先级,实现概率上的平衡。Splay 树直接用旋转调整树的形态,通过旋转改善树的平衡性。计算量小,效果好。
● Splay 树的旋转主要分为“单旋”和“双旋”。
所谓“单旋”,即把结点 x 与它的父结点交换位置,使结点 x 上升一层。“单旋”不会减少树的层数,对改善平衡性没有帮助。根据旋转方向,“单旋”又分为左旋(zag)与右旋(zig)。
所谓“双旋”,即两次“单旋”。“双旋”同时旋转结点 x,父结点 f 及祖父结点 g 等3个结点,能改善平衡性。“双旋”又分为“一字旋”与“之字旋”。
● Splay 树的旋转示意图

● Splay 树的基本操作是把结点旋转到树的根部,这样下次访问它时,只需查一次就 OK 了。
● Splay 树是动态树(LCT,Link Cut Tree)与树链剖分的基础。
● Splay 树曾经是最常使用的 BST。不过,现在经常使用 FHQ Treap 树实现很多传统的 Splay 树的题目。因为,FHQ Treap 树代码更容易写,效率也很高,且可做持久化。

【算法代码】

#include <bits/stdc++.h>
using namespace std;

const int maxn=2e6+5;
const int inf=0x3f3f3f3f;
int root,idx;

struct Node {
    int ch[2],val,fa;
    int size,cnt;
} tr[maxn];

void pushup(int x) {
    tr[x].size=tr[tr[x].ch[0]].size+tr[tr[x].ch[1]].size+tr[x].cnt;
}

void rotate(int x) {
    int y=tr[x].fa;
    int z=tr[y].fa;
    int k=(tr[y].ch[1]==x);
    int b=tr[x].ch[k^1];

    if(z) tr[z].ch[tr[z].ch[1]==y]=x;
    tr[x].fa=z;
    tr[y].ch[k]=b;
    if(b) tr[b].fa=y;
    tr[x].ch[k^1]=y;
    tr[y].fa=x;

    pushup(y);
    pushup(x);
}

void splay(int x,int k) {
    while(tr[x].fa!=k) {
        int y=tr[x].fa;
        int z=tr[y].fa;
        if(z!=k) {
            if((tr[y].ch[0]==x)^(tr[z].ch[0]==y)) rotate(x);
            else rotate(y);
        }
        rotate(x);
    }
    if(!k) root=x;
}

void insert(int x) {
    int u=root,p=0;
    while(u && tr[u].val!=x) {
        p=u;
        u=tr[u].ch[x>tr[u].val];
    }
    if(u) {
        tr[u].cnt++;
        pushup(u);
    } else {
        u=++idx;
        if(p) tr[p].ch[x>tr[p].val]=u;
        tr[u].ch[0]=tr[u].ch[1]=0;
        tr[u].fa=p;
        tr[u].val=x;
        tr[u].size=tr[u].cnt=1;
    }
    splay(u,0);
}

int get_pri_by_val(int x) {
    int u=root,p=0,res=0;
    while(u) {
        p=u;
        if(tr[u].val<x) {
            res+=tr[tr[u].ch[0]].size+tr[u].cnt;
            u=tr[u].ch[1];
        } else {
            u=tr[u].ch[0];
        }
    }
    if(p) splay(p,0);
    return res;
}

int get_val_by_pri(int k) {
    int u=root;
    while(true) {
        int ls=tr[tr[u].ch[0]].size;
        if(k<=ls) u=tr[u].ch[0];
        else if(k<=ls+tr[u].cnt) break;
        else k-=ls+tr[u].cnt, u=tr[u].ch[1];
    }
    splay(u,0);
    return tr[u].val;
}

int get_pre(int x) {
    int u=root,p=0;
    while(u) {
        if(tr[u].val<x) {
            p=u;
            u=tr[u].ch[1];
        } else u=tr[u].ch[0];
    }
    if(p) splay(p,0);
    return p;
}

int get_suc(int x) {
    int u=root,p=0;
    while(u) {
        if(tr[u].val>x) {
            p=u;
            u=tr[u].ch[0];
        } else u=tr[u].ch[1];
    }
    if(p) splay(p,0);
    return p;
}

void remove(int x) {
    int pre=get_pre(x),suc=get_suc(x);
    splay(pre,0);
    splay(suc,pre);
    int del=tr[suc].ch[0];
    if(!del || tr[del].val!=x) return;
    if(tr[del].cnt>1) {
        tr[del].cnt--;
        pushup(del),pushup(suc),pushup(pre);
    } else {
        tr[suc].ch[0]=0;
        pushup(suc),pushup(pre);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    insert(-inf);
    insert(inf);

    int T;
    cin>>T;
    while(T--) {
        int op,x;
        cin>>op>>x;
        if(op==1) insert(x);
        else if(op==2) remove(x);
        else if(op==3) cout<<get_pri_by_val(x)<<endl;
        else if(op==4) cout<<get_val_by_pri(x+1)<<endl;
        else if(op==5) {
            int pos=get_pre(x);
            if(pos) cout<<tr[pos].val<<endl;
        } else if(op==6) {
            int pos=get_suc(x);
            if(pos) cout<<tr[pos].val<<endl;
        }
    }
    return 0;
}

/*
in:
10
1 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598

out:
106465
84185
492737
*/



【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/138541955
https://blog.csdn.net/hnjzsyjyj/article/details/138522947
https://blog.csdn.net/hnjzsyjyj/article/details/138504578


 

IGV新手必看:5分钟搞定ChIP-seq/DAP-seq/ATAC-seq数据可视化(附常见报错解决方案) 本文为IGV新手提供了一份快速上手的实战指南,详细讲解了如何高效完成ChIP-seq、DAP-seq、ATAC-seq等数据的可视化。内容涵盖软件安装、基因组导入、文件格式转换与优化,并重点剖析了“导入后一片空白”等常见报错的根本原因与解决方案,帮助用户在5分钟内避开雷区,生成可用于发表的IGV专业图谱。 阅读详情

相关推荐

电商秒杀场景下,如何用Redis+Lua脚本实现原子性库存扣减(附完整代码)

本文针对电商秒杀场景下的高并发与超卖难题,详细解析了如何利用Redis的原子性命令与Lua脚本实现可靠的库存扣减。通过对比多种方案,阐述了Redis+Lua作为黄金搭档的技术原理,并提供了从基础扣减到预扣减模型的完整代码实现,确保在高并发下数据的一致性与系统性能。

weixin_29219539的博客 507

平衡树详解(Splay)

引入 先看例题:(洛谷 P3369 【模板】普通平衡树) 您需要写一种数据结构,来维护一些数,其中需要提供以下操作: 1.插入 xxx 数 2.删除 xxx 数(若有多个相同的数,因只删除一个) 3.查询 xxx 数的排名(排名定义为比当前数小的数的个数 +1+1+1 ) 4.查询排名为 xxx 的数 5.求 xxx 的前驱(前驱定义为小于 xxx,且最大的数) 6.求 xxx 的后继(后继定义为大于 xxx,且最小的数) 显然可以使用BST(二叉搜索树)完成,它的时间复杂度是 O(logn)O(log

Wu_while的博客 1万+

nsight-system教程

参考nsight-compute使用教程-CSDN博客。

youzjuer的博客 1895

文艺平衡树算法

一、文艺平衡树解决什么问题 您需要写一种数据结构,来维护一个有序序列。 其中需要提供以下操作:翻转一个区间,例如原有序列是5 4 3 2 1,翻转区间是[2,4],结果为5 2 3 4 1 二、文艺平衡树与普通平衡树 a[5]={ 5 , 4 , 3 , 1 , 2 }那么存入文艺平衡树之后,再中序遍历的结果应该还是:{ 5 ,4 ,3,1,2}。即下标从小到大,而不是里面的值从小到大!这是与普通平衡树的最大的不同!文艺平衡树经过rotate旋转之后,它的中序遍历是不变的(即,下标从小到大)。但是让这颗树的

稚始稚终的博客 3008

我用 AI Agent 全自动跑 COMSOL 仿真:从建模到后处理,踩了 10+ 个深坑

本文探讨了利用AI通过COMSOL Java API实现AI芯片液冷冷板全流程自动化仿真的实践。针对700W高功耗AI芯片的散热需求,构建了包含4颗Chiplet和微通道冷板的三维液冷模型。通过严格设计的Prompt工程,AI Agent成功完成了从几何建模到结果验证的全过程,最终实现了芯片最高温度54°C的良好散热效果。文章重点分享了10个关键问题的解决经验,包括流体连通性验证、网格顺序控制、离散阶数选择、收敛判据优化等,并建立了包含流场/热场/网格独立性的三重验证体系。实践表明,AI可高效处理重复性工作

sjjsjjsjjsjjsjj的博客 1057

Windows10系统添加虚拟网卡(Microsoft Loopback Adapter)的方法

1、按下win + R键,在其中输入:hdwwiz,然后 (enter) 2、点击下一步即可 3、其次选择【网络适配器】,然后点击【下一步】。 4、在厂商处选择Microsoft,网络适配器处选择【Microsoft Loopback Adapter】选项 ,点击【下一步】。 5、通过上面几个步骤的设置后,一块虚拟网卡的安装设置就算是完成了。 ...

一个懒鬼的博客 2万+

【数据结构】详细解读 Splay Tree(附完整代码)

本鱼干最近在家忙着玩,大脑许久不怎么用。昨日闲来无事,遂翻看书籍。正巧《机器学习》决策树这一块不是太熟悉。本打算品茶而观之,但发现有一树名Treap,觉得挺好玩,遂实现了一下,做了几个相关题目(用的STL中的map...因为懒),又深入发现了一种名为Splay的树,更加好玩,可苦于没有办法用STL里的东西代替它,遂于今日下午深入了解,并写成博客~~水经验~~ 分享之。

qq_25426559的博客 4519

利用ENVI处理TIF文件,把多个tif整合到一个完整的tif,例如2003-2011年的tif整合到一个tif上。

利用ENVI处理TIF文件,把多个tif整合到一个完整的tif,例如2003-2011年的tif整合到一个tif上。

unique_sir的博客 1万+

普通平衡树 Splay

普通平衡树,Splay

wanglianda2007的博客 1814

CAN总线数据采集与分析

在CAN总线数据采集中,数据采集是指从CAN网络中获取数据,并将其存储在本地或远程数据库中。数据源:明确数据源,如CAN总线、CANoe/CANalyzer工具等。数据格式:确定数据格式,如CAN消息、信号值、环境变量等。数据存储:选择数据存储方式,如本地文件、数据库、云存储等。在CAN总线数据分析中,数据分析是指对采集到的数据进行处理和分析,以提取有用的信息。数据处理:对采集到的数据进行处理,如滤波、去噪、归一化等。数据分析:对处理后的数据进行分析,如统计分析、趋势分析、故障诊断等。数据可视化。

闲人编程的博客 4050

Ceph入门到精通-更换osd、扩容osd

【代码】Ceph入门到精通-更换osd、扩容osd。

隔壁老瓦的专栏 1549

Splay 模板 洛谷P3369 普通平衡树

Splay 模板 洛谷P3369 普通平衡树 什么也不说上代码 这代码我也不求人看懂,操作原理有点复杂,不是很想讲,以后再来填坑吧! #include <bits/stdc++.h> using namespace std; const int maxn=1000000; class Splay{ private: int ch[maxn][2],f[maxn]...

qq_33437973的博客 280

基于深度确定性策略梯度的永磁同步电机强化学习控制方法

本文提出了一种基于深度确定性策略梯度(DDPG)的永磁同步电机(PMSM)电流内环智能控制方法。首先建立了PMSM在d-q坐标系下的数学模型,分析了传统矢量控制双闭环系统中PI控制器的局限性。针对电流内环控制问题,设计了包含电流跟踪误差、转速信息和历史控制量的状态空间,将电压输出作为动作空间,并构建了兼顾跟踪精度和响应速度的奖励函数。通过DDPG算法训练智能体,使其能够自适应调整控制策略。仿真结果表明,与固定参数的PI控制器相比,DDPG控制器在动态响应速度和抗干扰能力方面具有明显优势,为PMSM高性能控制

huanghm88的专栏 104

洛谷P3369【模板】普通平衡树

本蒟蒻最近刚刚学会平衡树,特来写篇博客以加深印象。 (我的意思是若写的不好望各位奆佬多多包含!) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入 x 数 删除 x 数(若有多个相同的数,因只删除一个) 查询 x 数的排名(排名定义为比当前数小的数的个数 +1 。若有多个相同的数,因输出最小的排名) 查询排名为 x 的数 求 x 的前驱(...

L_Y_T020321的博客 631

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【Splay】 洛谷 P3369 【模板】普通平衡树

https://www.luogu.org/problemnew/show/P3369 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入xx数 删除xx数(若有多个相同的数,因只删除一个) 查询xx数的排名(排名定义为比当前数小的数的个数+1+1。若有多个相同的数,因输出最小的排名) 查询排名为xx的数 求xx的前驱(前驱定义为小于xx,且...

qq_41037114的博客 330

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

洛谷P3369 【模板】普通平衡树(Splay)

题面 传送门 题解 鉴于最近的码力实在是弱到了一个境界……回来重新打一下Splay的板子……竟然整整调了一个上午…… //minamoto #include<bits/stdc++.h> #define R register #define inline __inline__ __attribute__((always_inline)) #define fp(i,a,b) for(R ...

weixin_30779691的博客 96

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【洛谷 P3369】【模板】普通平衡树

提高+/省选−

2601_96575140的博客 487

洛谷 P3369 【模板】普通平衡树 Treap/Splay

写一个数据结构来提供以下操作: 插入 xxx 删除 xxx (多个相同则只删除一个) 查询 xxx 的排名(从 111 开始数) 查询排名为 xxx 的数 求 xxx 的前驱 (前驱定义为 max⁡{k∣k<x}\max\{k|k<x\}max{k∣k<x}) 求 xxx 的后继 (后继定义为 min⁡{k∣k>x}\min\{k|k>x\}min{k∣k>x...

wineandchord 413

洛谷 P3369 【模板】普通平衡树

原题地址:https://www.luogu.org/problemnew/show/P3369 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入xx数 删除xx数(若有多个相同的数,因只删除一个) 查询xx数的排名(排名定义为比当前数小的数的个数+1+1。若有多个相同的数,因输出最小的排名) 查询排名为xx的数 求xx的前驱(前驱定义为小...

whisperlzw的博客 253

【模板】普通平衡树(洛谷P3369)

【代码】【模板】普通平衡树(洛谷P3369)

GordrnGhost的博客 392

洛谷 P3369 【模板】普通平衡树 【无旋treap、Splay、pb_ds】

题目链接 题意: 写一种数据结构,来维护一些数,其中需要提供以下操作: 插入 xx 数 删除 xx 数(若有多个相同的数,因只删除一个) 查询 xx 数的排名(排名定义为比当前数小的数的个数 +1+1 ) 查询排名为 xx 的数 求 xx 的前驱(前驱定义为小于 xx,且最大的数) 求 xx 的后继(后继定义为大于 xx,且最小的数) 题解: 平衡树的模板题,但是treap相较于其他的BST更好写、更好理解 #include<iostream> #include<sstream>

qq_50554695的博客 399

bzoj 3224 //3224: Tyvj 1728 普通平衡树 洛谷 P3369 【模板】普通平衡树 题解 splay

bzoj 3224 //3224: Tyvj 1728 普通平衡树 洛谷 P3369 【模板】普通平衡树 题解 splay 入门详见https://blog.csdn.net/mrcrack/article/details/103117899 Accepted 3180 kb 800 ms C++/Edit 5465 B //3224: Tyvj 1728 普通...

mrcrack的博客 251

手搓平衡树:一颗B-树,一颗AVL树,一颗RB树,一颗Splay树,一颗带旋Treap,一颗无旋fhq-Treap,一颗01Trie

平衡树锦集:AVL树,红黑树,B-树,带旋Treap,无旋fhq-Treap,Splay树的全代码实现,除B-树外的洛谷P3369验证。

qq_16762209的博客 795
上一篇: 洛谷 P3224:[HNOI2012] 永无乡 ← Splay树 + 并查集
下一篇: 洛谷 P2840:纸币问题 2 ← 动态规划 + 有序完全背包
hnjzsyjyj
博客等级 码龄18年 5332粉丝 2001原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址