Splay 板子

Python+pytest+requests 自动化测试框架 环境准备 本次选用的是Python+Pytest+requests来搭建自动化框架,需要有 Python 环境(3.x 版本),安装pytest和requests,不会安装的自行去网上搜教程。 关于 Pytest 的基本使用,这里不作讲解,不清楚的可以看我之前的文章。 简单 Demo 我们先创建一个项目,取名api-test,然后在下面创建一个test_api.py的文件 # test_api.py import pytest import requests def test_01(): 阅读详情
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int INF=0x3f3f3f3f;
inline int read(){
   int s=0,w=1;
   char ch=getchar();	
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}

const int N=2e5+5;
struct node{
	int s[2],p,v;
	int size,cnt;
	void init(int _p,int _v){
		p=_p, v=_v;
		size=cnt=1;
	}
}tr[N];
int idx,root;

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

void rotate(int x){
	int y=tr[x].p, z=tr[y].p;
	int k=tr[y].s[1]==x;
	tr[z].s[tr[z].s[1]==y]=x, tr[x].p=z;
	tr[tr[x].s[k^1]].p=y, tr[y].s[k]=tr[x].s[k^1];
	tr[y].p=x, tr[x].s[k^1]=y;
	pushup(y), pushup(x);
}

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

void insert(int v){
	int u=root, p=0;
	while(u && tr[u].v!=v) p=u, u=tr[u].s[v>tr[u].v];
	if(u) tr[u].cnt++, tr[u].size++;
	else{
		u=++idx;
		if(p) tr[p].s[v>tr[p].v]=u;
		tr[u].init(p,v); // update the msg of the new node
	}
	splay(u,0);
}

void find(int v){
	int u=root;
	if(!u) return;
	while(v!=tr[u].v && tr[u].s[v>tr[u].v]) u=tr[u].s[v>tr[u].v];
	splay(u,0);
}

int pre(int v){
	find(v);
	int u=root;
	if(tr[u].v<v) return u; // 如果树中所有数的值都没有 v 大,那么 v 的前驱一定是 u 
	u=tr[u].s[0];
	while(tr[u].s[1]) u=tr[u].s[1];
	return u;
}

int suf(int v){
	find(v);
	int u=root;
	if(tr[u].v>v) return u; // 如果树中所有数的值都没有 v 小,那么 v 的后继一定是 u 
	u=tr[u].s[1];
	while(tr[u].s[0]) u=tr[u].s[0];
	return u;
}

void remove(int v){
	int pu=pre(v), su=suf(v);
	splay(pu,0);splay(su,pu);
	int u=tr[su].s[0]; // the point to remove;
	if(tr[u].cnt>1) tr[u].cnt--, splay(u,0);
	else tr[su].s[0]=0;
}

int rk_for_num(int k){
	int u=root;
	while(true){
		int ls=tr[u].s[0];
		if(tr[ls].size+tr[u].cnt<k) k-=tr[ls].size+tr[u].cnt,u=tr[u].s[1];
		else if(tr[ls].size>=k) u=tr[u].s[0];
		else return tr[u].v;
	}
}

int num_for_rk(int v){
	find(v);
	return tr[tr[root].s[0]].size+1-1;
}

int main(){
	int m; cin>>m;
	insert(-INF), insert(INF);
	while(m--){
		int op, x; op=read(), x=read();
		if(op==1) insert(x);
		else if(op==2) remove(x);
		else if(op==3) cout<<num_for_rk(x)<<endl;
		else if(op==4) x++,cout<<rk_for_num(x)<<endl;
		else if(op==5) cout<<tr[pre(x)].v<<endl;
		else if(op==6) cout<<tr[suf(x)].v<<endl;
	}
	return 0;
}
系统架构设计(以飞控系统、航电系统、机电管理系统、电子电气架构为例) 系统架构涉及对系统的结构和行为进行高层次的描述。它包括系统的组成部分、这些部分之间的关系、与外部环境的交互方式,以及满足特定功能和非功能性需求的方法。系统架构定义了系统的总体设计蓝图,指导系统的开发、集成、部署和维护。系统架构设计的目的是通过合理的结构和设计原则,确保系统能够高效、稳定、安全地运行,满足当前和未来的需求,同时具备良好的维护性、扩展性和可持续性。良好的系统架构不仅能够提高系统的开发效率和运行性能,还能降低长期的维护和运营成本,支持系统的持续演进和技术更新。 阅读详情

相关推荐

VSCode + ESP-IDF 项目搭建及配置

VSCode 搭建 ESP-IDF 开发环境

weixin_51358957的博客 2万+

splay板子

解锁新技能,伸展树,splay基于平衡二叉树,可以查询前驱和后继,保证差值最小哦 以x为主人公 右旋 无图(自行脑补qaq) y节点为x节点的父节点,z节点为y节点的父节点(前置) 1.如果x节点存在右节点,那么就把它作为y节点的左儿子,更新x的右儿子的父亲为y节点。 void right_rotate(int x){ int y=fa[x]; int z=fa[y]; fa[rig...

qq_36172410的博客 204

基于FastLIO2与TEB算法的机器狗自主导航系统实战

本文详细介绍了如何为机器狗构建一套基于FastLIO2与TEB算法的自主导航系统。通过整合FastLIO2激光惯性里程计实现精准定位,并采用TEB局部规划器进行灵活路径规划与动态避障,解决了传统方案在复杂地形下反应慢、易碰撞的问题。文章提供了从环境搭建、算法部署、地图转换到系统调试的完整实战指南,帮助开发者实现机器狗的稳健自主行走。

beer8的博客 323

SPlay 板子

#include&lt;stdio.h&gt; #include&lt;string.h&gt; #include&lt;vector&gt; using namespace std; typedef long long ll; const int maxn=1e6+7; const int N=120005,INF=0x3f3f3f3f; struct Splay_Tree { st...

ii0789789789的博客 275

【iceberg数据一致性】iceberg如何保证高并发数据一致性

那么在高并发的时候,同时操作某张表时是如何运作的呢?其实这里iceberg引用了乐观锁的方法。其实在写入数据的时候是有一个验证的操作的,即在准备写入时会检查原文件和带写入文件的差异,如果存在本次写入数据以外的数据,则代表有其他操作已经更新了原文件,那么本次写入会取消,并重试写入的步骤,知道验证完成,写入完成,如此就保证了数据的一致性,并且也解决了HMS锁的问题。在使用iceberg写数据时,一直弄不清楚为什么iceberg写入快,并且能够保证数据的一致性。今天决定搞清楚这个问题,经过查询和理解,写下来。

你的博客 1045

ATAC-seq数据分析流程

Outline0. ATAC-seq原理0.1 染色体结构0.2 原理0.3 结果0.4 意义1. ATAC-seq数据分析流程1.1 上游分析(1)序列质控和比对(2)序列筛选1.2 下游分析1.3 进阶分析 0. ATAC-seq原理 0.1 染色体结构 0.2 原理 0.3 结果 0.4 意义 1. ATAC-seq数据分析流程 1.1 上游分析 (1)序列质控和比对 fastqc trim_golare bowtie2 mapping时要加上参数 --very-sensitive -X 2000

weixin_57830892的博客 1万+

SPLAY板子

3224: Tyvj 1728 普通平衡树 Time Limit: 10 SecMemory Limit: 128 MBSubmit: 11333Solved: 4840[Submit][Status][Discuss] Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 1. 插入x数 2. 删除x数(若有多个...

135

MIPI D-PHY TX 一致性测试实例解析 Part 03

本文之前,已经讨论了MIPI D-PHY TX的1.3.x和1.4.x的测试项,1.5.x的测试项相对较少,主要是用于时钟和数据通道相关的时序测量

一只豌豆象的博客 5189

splay板子整理

本质就是个平衡树。 具体到一道题,无非就是要考虑如何 1.每个节点维护什么信息。 2.如何维护splay(top,bottom等splay特色操作) 3.如何建树,建树规则如何实现。如何找到需要的节点。 4.结合其他数据结构(难) #include <bits/stdc++.h> using namespace std; //-----pre_def---- const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; typedef lo

sancpp的博客 317

scratch绘制四个三角形 2024年6月中国电子学会 图形化编程 scratch编程等级考试二级真题和答案解析

​ scratch绘制四个三角形 一、题目要求 2024年6月电子学会图形化编程Scratch等级考试二级真题 1、准备工作 1.保留默认角色小猫; 2.添加背景Stars。 2、功能实现 1 .隐藏角色小猫,设置画笔裙始位置为(0,0),画笔颜色为黄色,画笔的粗细为5; 2. 点击绿旗,绘制如下图所示图形,三角形的边长为50。 二、案例分析 1、角色分析 角色:小猫 2、背景分析 背景:Stars背景 3、前期准备 1. 保留默认的小猫不变 ​

青少年编程学习指导 1717

如何理解S参数的三大特性

提到S参数的时候经常会涉及一些概念,如无源性、因果性、互易性等,本文逐一介绍这些特性的概念、成因以及判断方式。

一只豌豆象的博客 4500

Splay平衡树板子

Splay平衡树板子

bunny_1024的博客 235

【Windows Server 2019】活动目录 (Active Directory) ——将计算机加入域和脱离域

博文介绍了如何将计算机加入AD域和脱离AD域,包括加入域,验证客户机加入到域后的信息,使用域账户用户在客户机上登录,使用本地账户用户在计算机上登录,脱离域。

VMware, Windows, Linux, Cisco, Container, Kubernetes, Kali 6169

Splay 板子学习

介绍 Spaly是伸展树 也是对二叉查找树的一种改进,虽然它并不能保证树一直是“平衡”的,但对于伸展树的一系列操作,我们可以证明其每一步操作的平摊复杂度都是O(log n)。所以从某种意义上说,伸展树也是一种平衡的二叉查找树。而在各种树状数据结构中,伸展树的空间要求与编程复杂度也都是很优秀的 处理问题 伸展树在区间插入,区间删除,区间翻转,区间旋转的问题中应用较多。 参考 入门解析: h...

神回 453

深度学习工具包 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")

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

P2596(Splay 解决板子以及思路)

题目一看就知道是一个平衡树, 但是这道题目并没有用 Treap 来写, 转而用 Splay 写了一下,也借鉴了以下板子 Splay 和 Treap 相比最大区别可能就是 多了一个 splay 操作,还有 Splay 不会像 Treap 那样只要加入节点就会立刻更新整个结构,而是根据询问,不断地把节点提升到根部,从而改变整个树结构内容,通过不断地均分复杂度,所以可能会跑的非常之快,所以相比Tre...

qq_40924940的博客 310

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

splay好板子

找到一份比较好的板子,链接https://blog.youkuaiyun.com/crazy_ac/article/details/8034190 #include<cstdio> #include<cstdlib> const int inf = ~0u>>2; #define L ch[x][0] #define R ch[x][1] #define ...

weixin_30425949的博客 89

数据结构板子——splay

splay

weixin_51771856的博客 369

POJ - 3481 splay板子

Double Queue 默写splay板子 很多细节问题。。。 #include<cstdio> #include<iostream> using namespace std; #define maxn 1000005 int root; int tot=0; int ch[maxn][2],par[maxn]; int cnt[maxn...

asmallfish1985的博客 121

bzoj 3224 splay板子

觉得模块化起来挺好看的,也不容易错^_^#include &lt;cstdio&gt; #define lf ch[x][0] #define rg ch[x][1] #define rep(i,j,k) for (i=j;i&lt;=k;i++) const int inf=2e9+1,N=1e5+5; using namespace std; int n,i,od,x,o; struct bs...

Orzage的博客 359

粗糙splay板子

存一个。 #include&lt;bits/stdc++.h&gt; using namespace std; const int maxn = 1e5 + 5; struct Splay { //f[i]表示i的父结点,ch[i][0]表示i的左儿子,ch[i][1]表示i的右儿子. //key[i]表示i的关键字(即结点i代表的那个数字),cnt[i]表示i结点的关键字出现的次数(相当...

Cymbals的博客 229

又复习了一遍splay板子

void right_rotate(int x) { int y=fa[x]; int z=fa[y]; fa[rightson[x]]=y; if (rightson[x]) { leftson[y]=rightson[x]; } fa[x]=z; if (z){ if (leftson[z]==y) leftson[z]=x; else rightson[z]=x; } rig...

qq_36172410的博客 173

splay树---板子题

文章目录问题 A: Splay —— Ver.I题目描述输入输出样例输入样例输出代码1代码2问题 B: 宠物收养所(Splay —— 前驱后继操作)题目描述输入输出样例输入样例输出提示代码 问题 A: Splay —— Ver.I 问题 B: 宠物收养所(Splay —— 前驱后继操作) 问题 A: Splay —— Ver.I 题目描述 输入 第一行包含一个整数n,表示初始序列的长度。 以下n行每行包含一个整数,描述初始的序列。 接下来一行包含一个整数n,表示插入操作的数目。 以下m行每行描述一个操作。

NP_hard的博客 506

个人整理的数组splay板子,指针的写的太丑了就不放了。。

splay的板子。。 由于被LCT榨干了。。所以昨天去学了数组版的splay,现在整理一下板子。。 以BZOJ3224和3223为例题。。暂时只有这些,序列的话等有时间把维修序列给弄上来!! BZOJ 3224 平衡树的操作 #include <bits/stdc++.h> #define INF 0x3f3f3f3f #define full(a, b) memset(a, b, s...

weixin_34061042的博客 138

bzoj3224 splay板子

开始学习新知识:splay——tree 是个板子题,学习splay可以看博客 https://blog.youkuaiyun.com/Clove_unique/article/details/50630280 #include<iostream> #include<cstring> #include<cstdio> using namespace std; ...

weixin_30840573的博客 115

Splay—板子

【代码】Splay—板子。

A_Bright_CH的博客 179
上一篇: 归并排序板子
下一篇: windows10 修改用户名
Tenshi0x0
博客等级 码龄7年 6粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值