uva11996 - Jewel Magic 伸展树

伸展树,LCP(uva,11996) 讲道理,基于哈希值的字符串算法真的很不错。因为unsigned long long高达1e19,而算法竞赛中字符串长度不可能大于1e6,毕竟如果再大,那就连经典字符串算法都无法在短时间求得结果了O(nlongn)。所以重复的概率为1e6*1e6/1e19=1e-7,即只有0.00001%的概率会重复。 在本题中HASH值取3是可以的,而2是不可以的。因为2是unsigned long long最 阅读详情

Problem J

Jewel Magic

I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At anytime, if you point to two jewels and ask me, what is the length of the longest common prefix (LCP) of jewel strings starting from these two jewels, I can answer your question instantly. Can you do better than me?

Formally, you'll be given a string of 0 and 1. You're to deal with four kinds of operations (in the following descriptions, L denotes the current length of the string, and jewel positions are number 1 to L numbered from left to right):

1 p c

Insert a jewel c after position p (0<=p<=L. p=0 means insert before the whole string). c=0 means emerald, c=1 represents pearl.

2 p

Remove the jewel at position p (1<=p<=L).

3 p1 p2

Reverse the part starting from position p1, ending at position p2 (1<=p1 < p2<=L)

4 p1 p2

Output the LCP length of jewel strings starting from p1 and p2 (1<=p1 < p2<=L).

Input

There will be several test cases. The first line of each test case contains an integer n and m (1<=n,m<=200,000), where n is the number of pearls initially, m is the number of operations. The next line contains a 01 string of length n. Each of the next m lines contains an operation. The input is terminated by end-of-file (EOF). The size of input file does not exceed 5MB.

Output

For each type-4 operation, output the answer.

Sample Input

12 9
000100001100
1 0 1
4 2 6
3 7 10
4 1 7
2 9
4 3 11
4 1 9
4 1 7
4 2 3

Output for the Sample Input

3
6
2
0
3
2

  长度为N的0,1串,四种操作。

  1 p c,在第p个字符之后插入字符c。

  2 p ,删除第p个字符,后面的字符往前移。

  3 p1 p2,反转第p1到p2个字符。

  4 p1 p2,输出p1开始和p2开始的两个后缀的LCP。


  首先建立虚拟开始结点和结束结点,root是开始结点,root->ch[1]是结束结点,以root->ch[1]->ch[0]为根建立01串的树,这个可以像线段树那样二分建立。对于1,2,3操作,都用range截出相应的一段操作就行了,对于4操作,可以二分长度L,然后截出(x,x+L)和(y,y+L),判断这两个串相不相等,用hash值来判断比较好,因此对于每个结点我们还需要h1和h2代表以这个结点为根的串的正向hash值和倒过来的hash值,维护的时候根据hash值的定义有h1=ch[0]->h1*powers[ch[1]->s+1]+v*powers[ch[1]->s]+ch[1]->h1,h2=ch[1]->h2*powers[ch[0]->s+1]+v*powers[ch[0]->s]+ch[0]->h2,这样我们只需要比较截出来的两段hash值是否相等,其实只用比较h1就行了,但为了防止冲突发生,把h1和h2都比较一下更保险。

#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-9
#define MAXNODE 105
#define MOD 10000007
#define SIGMA_SIZE 4
typedef long long LL;
using namespace std;

const int MAXN=400020;
unsigned powers[MAXN];

struct Node *null,*pit;
struct Node{
    Node* ch[2];
    int s;
    int flip;
    int v;
    unsigned h1,h2;

    Node(){}
    Node(int v):s(1),flip(0),v(v),h1(v),h2(v){
        ch[0]=ch[1]=null;
    }
    void* operator new(size_t){
        return pit++;
    }
    int cmp(int k) const{
        int d=k-ch[0]->s;
        if(d==1) return -1;
        return d<=0?0:1;
    }
    void maintain(){
        s=ch[0]->s+ch[1]->s+1;
        h1=ch[0]->h1*powers[ch[1]->s+1]+v*powers[ch[1]->s]+ch[1]->h1;
        h2=ch[1]->h2*powers[ch[0]->s+1]+v*powers[ch[0]->s]+ch[0]->h2;
    }
    void reverse(){
        flip^=1;
        swap(ch[0],ch[1]);
        swap(h1,h2);
    }
    void pushdown(){
        if(flip){
            flip=0;
            ch[0]->reverse();
            ch[1]->reverse();
        }
    }
}pool[MAXN];

void init_null(){
    null=new Node();
    null->s=0;
}

void rotate(Node*& o,int d){
    Node* k=o->ch[d^1];
    o->ch[d^1]=k->ch[d];
    k->ch[d]=o;
    o->maintain();
    k->maintain();
    o=k;
}

//k>=1
void splay(Node*& o,int k){
    o->pushdown();
    int d=o->cmp(k);
    if(d==1) k-=o->ch[0]->s+1;
    if(d!=-1){
        Node* p=o->ch[d];
        p->pushdown();
        int d2=p->cmp(k);
        int k2=(d2==0?k:k-p->ch[0]->s-1);
        if(d2!=-1){
            splay(p->ch[d2],k2);
            if(d2==d) rotate(o,d^1);
            else rotate(o->ch[d],d);
        }
        rotate(o,d^1);
    }
}

struct SplaySequence{
    char* s;
    Node* root;

    // update dummy nodes
    //root: dummy min node
    // root->ch[1]: dummy max node
    // root->ch[1]->ch[0]: actual sequence
    void update_dummy(){
        root->ch[1]->maintain();
        root->maintain();
    }

    //[L,R)
    Node* build(int L,int R){
        int mid=L+(R-L)/2;
        Node* o=new Node(s[mid]);
        if(L<mid) o->ch[0]=build(L,mid);
        if(mid+1<R) o->ch[1]=build(mid+1,R);
        o->maintain();
        return o;
    }
    Node* build(char* s){
        this->s=s;
        root=new Node('[');
        root->ch[1]=new Node(']');
        root->ch[1]->ch[0]=build(0,strlen(s));
        update_dummy();
        return root;
    }

    //[L,R) L>=1
Node*& range(int L,int R){
    splay(root,L);
    splay(root->ch[1],R-L+1);
    return root->ch[1]->ch[0];
}

}ss;

int N,M;
char str[MAXN];

int main(){
    freopen("in.txt","r",stdin);
    powers[0]=1;
    for(int i=1;i<MAXN;i++) powers[i]=powers[i-1]*3137;
    while(scanf("%d%d%s",&N,&M,str)!=EOF){
        pit=pool;
        init_null();
        ss.build(str);
        int op,x,y;
        while(M--){
            scanf("%d%d",&op,&x);
            if(op==1){
                scanf("%d",&y);
                ss.range(x+1,x+1)=new Node(y+'0');
                ss.update_dummy();
            }
            else if(op==2){
                ss.range(x,x+1)=null;
                ss.update_dummy();
            }
            else if(op==3){
                scanf("%d",&y);
                ss.range(x,y+1)->reverse();
                ss.update_dummy();
            }
            else{
                scanf("%d",&y);
                //[L,R)
                int L=0,R=ss.root->s-y;
                while(L+1<R){
                    int mid=L+(R-L)/2;
                    unsigned h1=ss.range(x,x+mid)->h1;
                    if(h1==ss.range(y,y+mid)->h1) L=mid;
                    else R=mid;
                }
                printf("%d\n",L);
            }
        }
    }
    return 0;
}



基于 STM32 单片机的实验室多参数安全监测系统设计与实现 本系统以 STM32F103C8T6 单片机为核心,集成温湿度监测、烟雾检测、气体泄漏报警、人体移动监测等功能模块,通过 OLED 显示屏实时显示数据,并支持 Wi-Fi 远程传输。系统可对实验室异常环境参数(如高温、烟雾、燃气泄漏)及非法入侵实时报警,保障实验室安全。本文从硬件选型、电路设计到软件实现提供了完整的实验室安全监测系统方案,可根据实际需求调整传感器类型和通信方式,适用于科研、教学等场景的环境安全防护。:可增加继电器模块控制通风设备或切断电源,集成 ZigBee 组网实现多实验室联动监测。 阅读详情

相关推荐

发那科机器人Modbus通讯配置全攻略:从IP设置到信号调试

本文详细介绍了发那科机器人Modbus通讯的配置方法,从基础认知到IP设置、端口配置、信号调试及故障排查。重点讲解了UOP和DI/DO信号的配置技巧,帮助工程师快速实现机器人与PLC的稳定通讯,提升自动化系统效率。

weixin_27872611的博客 621

UVA 11996 Jewel Magic(伸展树+字符串hash)

大白书例题。 4种操作,插入操作可以像普通的排序二叉树那样插入,也可以利用2次伸展操作把第k-1个伸展到根节点,以及把根节点的右子树中的第一个伸展到根节点右子树节点,再把要插入的节点插入到右子树的左子树。 删除操作也可以像刚才一样,先把第k-1个伸展到根,再把右子树中第2个伸展到右子树处,这样右子树的左子树就是要删除的节点。 反转操作是通过类似刚才的操作提取那一段,再把这一段的左右子树交换,

glq007的acm的奋斗 706

AMD锐龙笔记本隐藏玩法:分核降压+ PBO2超频全攻略(以5900HX/6900HX为例)

本文详细解析了AMD锐龙笔记本(以5900HX/6900HX为例)的分核降压与PBO2超频技术,帮助用户释放处理器隐藏性能。通过BIOS设置、Curve Optimizer参数调整及稳定性测试,实现性能提升与温度控制的完美平衡,适合硬件爱好者进阶调校。

weixin_30617737的博客 341

spaly区间翻转,分裂,合并!UVA11922,UVA11996也是个不错的spaly

#include #include #include using namespace std; struct Node { Node *ch[2]; int s,v,flip; int cmp(int k) { int d=k-ch[0]->s; if(d==1) return -1; return d<=0?0:1;

nucshiyilang的博客 546

ROS2多线程处理RTSP视频流避坑指南:OpenCV解码丢帧问题解决方案

本文针对ROS2中处理RTSP视频流时OpenCV解码丢帧的常见问题,提供了专业的解决方案。通过深入分析单线程模型的瓶颈,提出并详细拆解了基于生产者-消费者多线程模型的健壮实现方案,有效分离数据采集与处理,从而显著提升视频流的稳定性和流畅度。

weixin_29199873的博客 168

PyTorch ModelNet点云数据集加载实战:从下载到Dataset类完整实现

在三维视觉与点云处理领域,数据集是算法研发的基石。ModelNet作为三维物体分类的基准数据集,其地位类似于图像领域的MNIST,是入门和评估模型性能的通用标准。理解其数据格式与加载原理,是进行点云分类、分割等任务的关键前置步骤。通过PyTorch的Dataset类,开发者可以构建高效的数据管道,将原始点云文件转换为神经网络可直接处理的张量格式,这一过程涉及数据采样、归一化、特征组装等核心操作,直接影响模型的训练效率和最终性能。本文聚焦于ModelNet10/40数据集,详细解析其目录结构,并提供一套稳健的

weixin_29032337的博客 280

Uva 11996 Jewel Magic (Splay)

Jewel Magic Description I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At an...

weixin_30914981的博客 137

ego-planner启动参数深度解析:从配置到实战避障应用

本文深入解析EGO-Planner启动参数的配置与实战应用,重点探讨无人机自主导航中的避障性能优化。通过环境感知、运动约束和算法控制三类参数的详细说明,结合ROS和RViz工具,提供从基础配置到高级调优的完整指南,帮助开发者提升无人机在复杂场景下的规划效率和安全性。

rum55的博客 246

伸展树uva11996

不知道哪错了,一直超时。。。 #include #include #include #include #include #include #include #include #include #include #include #define Key_value ch[ch[root][1]][0] using namespace std; typedef unsigned LL; const

龙崎的专栏 694

【MATLAB代码】蚁群算法(Ant Colony Optimization, ACO)路径规划(避障)仿真程序,订阅专栏后可直接查看完整源代码

基于蚁群算法的路径规划系统。可自定义起点、终点和障碍物地图,系统通过蚁群算法自动计算最优路径,并输出路径坐标、障碍物地图和收敛曲线。完整MATLAB源代码直接运行。适用于复杂障碍环境下的路径优化问题。

985工科博士毕业,专攻定位、导航和滤波等算法研究。从业10年,主要使用MATLAB 3091

STM32F103VCT6+W5500 TCP 服务端通信

STM32F103VCT6 W5500的TCP连接通讯的程序

坚韧与专注 7818

UVA 11996 Jewel Magic(伸展树)

原题链接Problem DescriptionI am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At anyti

ZhaoYi1222的博客 1479

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

UVa 11996 Jewel Magic 伸展树

I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At anytime, if you point to two

SCUT_Pein 1219

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

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

UVA 11996 Jewel Magic splay+字符串hash

给一个长度为n的01串,m个操作: 1 p

Broken Wings 768

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

UVA-11996-Jewel Magic(FHQTreap版)

题目链接:UVA-11996-Jewel Magic 题目大意: 给你一个010101序列,要求支持一下四个操作 输入 操作 111 ppp ccc 在数列第ppp个数字之后插入ccc 222 ppp 删除第ppp个位置的元素 333 p1p_1p1​ p2p_2p2​ 将第p1p_1p1​到第p2p_2p2​个元素之间的元素翻转 444 p1p_1p1​ p2p_2p2​ 输出第以p1p_1p1​开始和以p2p_2p2​开始的串的LCPLCPLCP 多组数据n,m≤2000

lycccccccc的博客 243

UVA 11996 Jewel Magic

UVA_11996 这个题目前三个操作都是典型的splay的操作,但是第四个操作之前没见过,我以前只用字典树+二分求过任意两个串的LCP,但这次是在splay上便一时间无从下手。后来看了别人的代码发现也是基于二分的,而至于如何判断二分出来的前缀是相同的,则直接用哈希值去比较了。 至于直接用哈希值判断两个字符串是否相等,我一开始也觉得很不靠谱,后来分析了一下发现虽然不靠谱但不靠谱的概...

weixin_30402085的博客 93

uva11996Jewel Magic (1.二分 分块 hash)(2.splay)

I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At anytime, if you point to two

zjy2015302395的博客 441

UVA 11996 Jewel Magic Splay+Hash

Description Problem J Jewel Magic I am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part

Azarath Metrion Zinthos 1364

UVA 11996 Jewel Magic (splay求两个后缀的LCP)

题目链接 题意:一个长度为n的01串(n 题解:对于一个静态的字符串,询问其两个后缀的最长LCP,可以用hash+二分的方法,O(lgn)的复杂度求解一次询问。 此题对字符串有添加、删除和区间的翻转的操作,所以我们考虑用splay维护串的hash值。 具体而言,我们维护以这个点为根的子树的点的个数和对应串的hash值。对于区间翻转操作而言,仅仅维护这些值是不行的,我还要维护以这个点为根的子

madaidao的专栏 590

UVA 11996 splay

点击打开链接 题意:给一个序列,还有四个操作,1是在第p个字符后面加入c,2是删除第p个字符,3是区间反转,4是询问p1和p2开头的字符串的lcp 思路:除了正常的splay以外,需要多维护一个哈希值,然后二分长度比较哈希值即可#include #include #include #include #include using namespace std; typedef long

Dan__ge的博客 473

UVA - 11996(splay入门)

本题目的操作是维护01序列。 并需要动态比较序列当前任意两个位置后缀的LCP。 那么只需要用splay维护序列的同时,再维护一个域(当前所在子树01序列的hash值),查找时就可以用伸展树的分裂和合并操作提取所需子树hash值,然后二分即可。 #pragma comment(linker, "/STACK:1024000000,1024000000") #include #include

playwfun的专栏 514

UVA 11996 Splay + LCP + Hash + 区间翻转 插入 删除

【题意】给出一个长度为n的01串,有m个操作。操作有以下几种:               1 p c在第p个字符后插入c               2 p    删除第p个字符               3 p1 p2 翻转p1到p2的字符串               4 p1 p2 求从p1开始和p2开始的两个后缀的LCP 【解题方法】              参见白书

I good vegetable a! 817

堆 优先队列

首先看完全二叉树的定义: 若设二叉树的深度为h,除第 h 层外,其它各层 (1~h-1) 的结点数都达到最大个数,第 h 层所有的结点都连续集中在最左边,这就是完全二叉树。   如果一个完全二叉树的某个结点值都不大于或小于他的父结点,那就叫做堆。根结点是所有结点里最大的叫大根堆,最小的叫小根堆。   比如:  9-1 a是大根堆,9-2 a是小根堆,剩下的都不是堆(因为不是完全二叉树)

2234
上一篇: uva11922 - Permutation Transformer 伸展树
下一篇: Codeforces Round #283 (Div. 2) D. Tennis Game
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值