主席树模板

主席树模板总结及题集 介绍篇:http://blog.youkuaiyun.com/metalseed/article/details/8045038  -> 理解篇(配图比较生动):http://blog.youkuaiyun.com/regina8023/article/details/41910615  -> 题目:poj2104 区间查询第k大元素,非递归写法,非递归不好进行回溯操作,递归更好写一些 #include #inc 阅读详情

5.3解锁新姿势
弱弱也会主席树啦

题目:查找区间第K小

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=100010;

struct Node{
int l,r;
int cnt;
}tr[N*4+N*17];

vector <int> num;
int a[N],idx,root[N];

int finx(int x)
{
    return lower_bound(num.begin(),num.end(),x)-num.begin();
}

int intree(int p,int l,int r,int x)
{
    int q=++idx;
    tr[q]=tr[p];
    if(l==r)
    {
        tr[q].cnt++;
        return q;
    }
    int mid=l+r>>1;
    if(x<=mid) tr[q].l=intree(tr[p].l,l,mid,x);
    else tr[q].r=intree(tr[p].r,mid+1,r,x);
    tr[q].cnt=tr[tr[q].l].cnt+tr[tr[q].r].cnt;
    return q;
}

int build(int l,int r)
{
    int p=++idx;
    if(l==r) return p;
    int mid=l+r>>1;
    tr[p].l=build(l,mid);
    tr[p].r=build(mid+1,r);
    return p;
}

int quary(int p,int q,int l,int r,int k)
{
    if(l==r) return l;
    int cnt=tr[tr[q].l].cnt-tr[tr[p].l].cnt;
    int mid=l+r>>1;
    if(cnt>=k) return quary(tr[p].l,tr[q].l,l,mid,k);
    else return quary(tr[p].r,tr[q].r,mid+1,r,k-cnt);
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        num.push_back(a[i]);
    }
    sort(num.begin(),num.end());
    num.erase(unique(num.begin(),num.end()),num.end());
    root[0]=build(0,num.size()-1);
    for(int i=1;i<=n;i++)
        root[i]=intree(root[i-1],0,num.size()-1,finx(a[i]));
    while(m--)
    {
        int l,r,k;
        scanf("%d%d%d",&l,&r,&k);
        printf("%d\n",num[quary(root[l-1],root[r],0,num.size()-1,k)]);
    }
}

ZYNQ新手必看:你的PS端DDR和QSPI配置真的对了吗?从原理到实操的避雷指南 本文深入解析ZYNQ PS端外设配置的关键要点,特别是DDR匹配和QSPI时钟优化的实战技巧。通过详细案例和配置清单,帮助开发者避免常见错误,确保系统稳定性和启动可靠性。适合ZYNQ新手和需要优化最小系统的开发者参考。 阅读详情

相关推荐

Cluster Computing期刊投稿实战:从格式调整到技术检查的全流程解析

本文详细解析了向Cluster Computing期刊投稿的全流程,涵盖心理准备、格式调整、参考文献处理及投稿系统操作。重点介绍了如何利用Springer LaTeX模板,特别是使用picins宏包解决作者简介排版难题,并强调了将BibTeX转换为BBL文件以避免技术审查陷阱,为研究者提供了一份实用的投稿指南。

weixin_28432777的博客 665

主席树【模板】

显然,如果我们将每次修改操作后的线段树存下来会消耗大量空间,但是,如果我们不存储修改操作后的整棵树,而是只增加新修改的点。对于每一次修改,我们只需要建立修改点和与其相关点的新节点就可以了,其他的点直接连在之前版本的树上就可以了。首先要明白主席树做的什么:对一棵线段树的节点进行修改,然后查询第。是在每次修改前先将上一个版本的节点复制一次。由此观察主席树的存储和线段树有明显的差异。的大佬创建的所以又叫做主席树。次操作后的线段树中的某个节点。主席树因为创建者名字缩写为。

qq_57730943的博客 441

51单片机超声波测距数码管显示并报警(Proteus 仿真)

HC-SR04超声波 实物图 使用方法 1、给TRIG端口至少10us 的高电平信号 2、模块自动发送 8 个 40khz 的方波,自动检测是否有信号返回 3、有信号返回,ECHO端口会输出一个高电平,高电平持续的时间就是超声波从发射到返回的时间 计算的话这里就不考虑温度的影响直接用声速340m/s Proteus仿真 HC-SR04可以用Proteus中的SRF04代替 下面附上代码 ...

m0_46254883的博客 1万+

主席树模板&可持久化数据结构介绍

引言 一、 可持久化数据结构的前提是其拓扑排序是不变的; 比如线段树,我们改变的总是它维护的数值,他的结构一旦定下来就不会变了; 二、 可持久化的核心思想是类似git操作,我们维护版本间的差异,而不是维护整个版本; 主席树 主席树又称可持久化线段树,其持久化的核心思想和引言的一致; 也就是我们每修改一个节点,我们就创建一个新的副本,并在副本的基础上进行修改; 如图所示,假设我们修改了1,2,4,81,2,4,81,2,4,8这条链,我们就创建这条链的一个备份,并且在这条链上修改; 每个版本我们都认为他

weixin_45724872的博客 450

统信UOS/麒麟Kylin OS下利用pyenv实现Python多版本开发环境搭建指南

本文详细介绍了在统信UOS和麒麟Kylin OS国产操作系统下使用pyenv搭建Python多版本开发环境的完整指南。从系统环境准备、pyenv定制安装到Python版本编译实战,提供了针对国产CPU架构的特殊优化方案和常见问题解决方法,帮助开发者高效管理不同Python版本需求。

sea99的博客 1050

ComfyUI 的 LoRA 训练:素材打标签与调优全攻略

标签是 LoRA 训练的"地基"——地基打不牢,后续调参再精细也难出好效果。记住:标签要"少而精",聚焦独特点,用触发词控效果。下一篇我们将讲解参数设置,让你的优质标签发挥最大价值~

2301_78150483的博客 3098

Super Mario HDU - 4417 主席树模板(二)

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...

Chter0的博客 252

FreeRTOS系统从入门到精通万字保姆级教程

例如,在基于ARM的硬件平台上,可能需要实现针对ARM处理器的上下文切换代码,并确保FreeRTOS能够正确地响应和处理ARM架构的中断。需要注意的是,在删除任务之前应确保任务已经完成了其所有重要的工作,并且没有其他的任务依赖于它,以避免数据丢失或系统不稳定。任务的优先级设定是其中的关键环节。在复杂的系统中,可能会有大量的任务需要同时运行,而这些任务的重要性和紧急程度各不相同。这通常包括创建初始任务(这些任务将负责系统的初始化和后续任务的调度)、设置系统时钟(以确保任务的准时调度和延时功能的正确性)等。

大模型大数据攻城狮的专栏 2067

【洛谷 3834】主席树(模板)

算法标签:主席树

forever_dreams的博客 456

使用PostgreSQL构建高可用数据库集群

在现代企业级应用中,数据库的高可用性已成为业务连续性的核心要求。PostgreSQL作为一款功能强大的开源关系型数据库,其高可用架构的设计直接影响着系统的稳定性和可靠性。

九天的专栏 1257

YOLO26 正式发布源代码!极致速度优化方案, 面向工业级落地的目标检测模型!

YOLO26 作为 Ultralytics 公司于 2025 年 9 月发布的最新一代目标检测模型,在架构设计和技术实现上展现了显著的创新。本文深入分析了 YOLO26 的核心架构改进和技术原理,重点探讨了其在边界框回归、推理流程、损失函数设计和优化算法方面的突破性进展。

魔改工程师的博客 1243

主席树算法模板

主席树代码模板 本篇博客仅提供代码模板,具体的算法思想,等本蒟蒻深度理解主席树之后补上。 题目描述 给定 n 个整数构成的序列 a,将对于指定的闭区间 [l, r] 查询其区间内的第 k 小值。 代码模板 #include<iostream> #include<time.h> #include<cstdio> #include<cmath> #include<queue> #include<stack> #include<vect

qq_45863423的博客 202

信号处理算法:自适应滤波_(8).自适应陷波器

自适应陷波器是一种强大的工具,广泛应用于电力系统、通信系统和生物医学信号处理等领域。通过自适应调整滤波器的参数,自适应陷波器可以在特定频率处形成陷波,从而有效地抑制噪声或干扰信号。常见的自适应算法包括LMS和RLS,它们各有优缺点,可以根据实际需求选择合适的算法。

2401_87715305的博客 1370

主席树模板题

主席树模板题 Keen On Everything But Triangle 题目描述 N sticks are arranged in a row, and their lengths are a1,a2,…,aN.There are Q querys....

VUno)UKGzseI 182

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

蓝牙模块HM-10手册

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

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

大半年没用过主席树了,手敲回顾下,20min手敲1A主席树模板。。 我感觉我线段树这一块拿捏的死死的!! 很easy #include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 2e5+7; int a[M],li[M],cnt=0; int rt[M*20],ls[M*20],rs[M*20],tr[M*20]; void up(int pre,int &o,int l,in

bjfu170203101的博客 247

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

模板:主席树

主席树模板 code: #include <bits/stdc++.h> using namespace std; typedef long long ll; bool Finish_read; template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar...

dieyi9889的博客 92

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

主席树 模板

#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<queue> #include<set> #include<stack...

explodee的博客 167
上一篇: E - Bin Packing Problem
下一篇: 树上背包2021.5.27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值