活跃区的操作序列的优先级单调不上升,所以每次undo的一定是一段区间。

以优先级为权值建立可持久化权值线段树,维护优先级在某区间内的最靠后的位置。

#include<cstdio>
const int N=300010,M=6000000;
int n,i,j,x,f[N],root[N],v[M],l[M],r[M],tot;
inline void read(int&a){
char c;bool f=0;a=0;
while(!((((c=getchar())>='0')&&(c<='9'))||(c=='-')));
if(c!='-')a=c-'0';else f=1;
while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';
if(f)a=-a;
}
inline int max(int a,int b){return a>b?a:b;}
int ins(int x,int a,int b,int c,int d){
int y=++tot;v[y]=max(v[x],d);
if(a==b)return y;
int mid=(a+b)>>1;
if(c<=mid)l[y]=ins(l[x],a,mid,c,d),r[y]=r[x];else l[y]=l[x],r[y]=ins(r[x],mid+1,b,c,d);
return y;
}
int ask(int x,int a,int b,int c){
if(!x)return 0;
if(b<=c)return v[x];
int mid=(a+b)>>1,t=ask(l[x],a,mid,c);
if(c>mid)t=max(t,ask(r[x],mid+1,b,c));
return t;
}
int main(){
for(read(n),i=1;i<=n;printf("%d\n",f[i++])){
read(x);
if(x>0)f[i]=x,root[i]=ins(root[i-1],0,n,0,i);
else f[i]=f[j=ask(root[i-1],0,n,-x-1)-1],root[i]=ins(root[j],0,n,-x,i);
}
return 0;
}

  

BZOJ4120 : [Baltic2015]Editor的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. [bzoj1269][AHOI2006文本编辑器editor] (splay模版题 or pb_ds [rope]大法)

    Description 这些日子,可可不和卡卡一起玩了,原来可可正废寝忘食的想做一个简单而高效的文本编辑器.你能帮助他吗?为了明确任务目标,可可对“文本编辑器”做了一个抽象的定义:   文本:由0个或 ...

  3. Bzoj1269 [AHOI2006]文本编辑器editor

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3678  Solved: 1380 Description 这些日子,可可不和卡卡一起玩了,原来可可正 ...

  4. Unity3D Editor 扩展

    官方教程:链接 EditorLayout API:链接 Handles API:链接 1.首先来个Inspector面板Editor的实现 要实现一个组件在Inspector中的Editor功能,首先 ...

  5. 推荐eclipse插件Properties Editor

    需求:一般我们在做"国际化"功能时,我们需要properties中文表示方式用unicode表示.eclipse默认properties文件编辑器不方便查看,需要我们查看常常查找u ...

  6. Delphi Code Editor 之 编辑器选项

    Delphi Code Editor 之 编辑器选项 可从Code Editor的右键菜单中选择“Properties”菜单项来查看编辑器选项.也可以从主菜单[Tools | Editor Optio ...

  7. SharedPreferences.Editor 的apply()与commit()方法的区别

    commit()的文档 官方文档如下: Commit your preferences changes back from this Editor to the SharedPreferences o ...

  8. Easyui datagrid editor为combobox时指定数据源

    当在datagrid行内部应用添加编辑操作时,引入combobox是非常方便的操作,我在引入combobox时对数据源这快做个总结,在做demo的过程中遇到个问题,就是当你选择了下拉框的值后点击保存, ...

  9. Microsoft Visual Studio 2008 未能正确加载包“Visual Web Developer HTML Source Editor Package” | “Visual Studio HTM Editor Package”

    在安装Microsoft Visual Studio 2008 后,如果Visual Studio 2008的语言版本与系统不一致时,比如:在Windows 7 English System 安装Vi ...

随机推荐

  1. 在CentOS 7 上搭建LAMP

    导读 要求:httpd的动态和静态资源分为两台主机提供,mysql也用单独一台主机.httpd服务提供虚拟主机,一个虚拟主机用于提供phpMyAdmin:另一个虚拟主机用于提供wordpress.安装 ...

  2. xcode SVN

    Mac上SVN的管理工具: CornerStone http://blog.csdn.net/wohaoxuexi/article/details/8444184 步骤: 1. import 项目到s ...

  3. compact过滤数组中的nil

    http://ruby-doc.org/core-2.2.0/Array.html#method-i-compact compact → new_aryclick to toggle source R ...

  4. Linux运维相关目录

  5. 重新编译安装gcc-4.1.2(gcc版本降级)之TFS安装

    wget http://gcc.parentingamerica.com/releases/gcc-4.1.2/gcc-4.1.2.tar.gz tar -zxfv gcc-4.1.2.tar.gz ...

  6. vista/win7/win8区别

    1. Vista的内核版本号是:Windows 6.0:         Windows 7的内核是:Windows 6.1:         Windows 8的内核是:Windows 6.2   ...

  7. 【Redis】Redis分布式集群几点说道

    Redis数据量日益增大,使用的公司越来越多,不仅用于做缓存,同时趋向于存储这一块,这样必促使集群的发展,各个公司也在收集适合自己的集群方案,目前行业用的比较多的是下面几种集群架构,大部分都是采用分片 ...

  8. boa服务器make错误

    参考: http://zhouyang340.blog.163.com/blog/static/3024095920121187544204/ http://blog.csdn.net/hongjiu ...

  9. 【转】仿百度输入框智能提示的js代码

    转自:http://www.jb51.net/article/40783.htm 对于我这个JS菜鸟,能找到这样的实属不容易啊!!! 刚开始老大让做这个功能,真是一点头绪都没有,万分感谢!!! 最近客 ...

  10. Java for LeetCode 036 Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...