活跃区的操作序列的优先级单调不上升,所以每次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. 在特定的action里使用validates

    http://guides.rubyonrails.org/v3.0.8/active_record_validations_callbacks.html#on 在特定的action里使用valida ...

  2. abstract class和interface的区别

    1. 引言 2. 概念引入 ●什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值.接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引 器.静态方法.静态 ...

  3. 如何分割一个utf8字符串(保证单个汉字的完整性)

    std::list<std::string> split_utf8_string(const std::string& text) { std::list<std::stri ...

  4. cc.game

    概述 使用cc.game单例代替了原有的cc.Application以及cc.AppControl. cc.game是Cocos2d-JS的游戏对象,主要职责包括,配置的读取,引擎的加载,游戏脚本的加 ...

  5. UTF8-GBK WideCharToMultiByte MultiByteToWideChar

    //MFC版本 CString UTF8ToGBK(const CString& strUTF8){ //确定转换为Unicode需要多少缓冲区(返回值也包含了最后一个NULL字符) int ...

  6. Spring MVC前台使用html页面作为视图,配置静态资源后Controller控制器不起作用的解决办法

    1.Spring MVC搭建项目的时候,想使用html页面作为前端的视图,你会发现html页面不能访问,原因是由于Spring拦截器将其拦截寻找控制器的缘故,解决办法就是配置静态资源: <mvc ...

  7. July 30th, Week 31st Saturday, 2016

    No matter how far you may fly, never forget where you come from. 无论你能飞多远,都别忘了你来自何方. No matter how fa ...

  8. Ubuntu 更新源

    1.首先备份Ubuntu12.04源列表 sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup (备份下当前的源列表) 2.修改更新源 ...

  9. Linux命令--文件权限和磁盘管理

    1.chmod chmod [ugoa][+-=][rwx] file 改变目录或者文件的权限. u是user,g是group,o是other,a是all. +是添加权限,-是去掉权限,=改变权限为. ...

  10. Ubuntu16.04 安装openjdk-7-jdk

    Ubuntu16.04 安装openjdk-7-jdk sudo apt-get install openjdk-7-jre 或者sudo apt-get install openjdk-7-jdk ...