http://codeforces.com/contest/1263/problem/E

题意:求合法的括号序列

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
#define pb push_back
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int M=1e6+;
int tree[M<<];
int lzmi[M<<];///最小前缀和
int lzma[M<<];///最大前缀和
char s[M];
void up(int root){
tree[root]=tree[root<<]+tree[root<<|];
lzma[root]=max(lzma[root<<],tree[root<<]+lzma[root<<|]);///右区间来选前缀时要考虑到左区间带进来的贡献
lzmi[root]=min(lzmi[root<<],tree[root<<]+lzmi[root<<|]);
}
void update(int p,int v,int root,int l,int r){
if(l==r){
tree[root]=lzmi[root]=lzma[root]=v;
return ;
}
int midd=(l+r)>>;
if(p<=midd)
update(p,v,lson);
else
update(p,v,rson);
up(root);
}
int main(){
int n;
scanf("%d%s",&n,s);
int nowpos=;
for(int i=;i<n;i++){
if(s[i]=='L')
nowpos=max(,nowpos-);
else if(s[i]=='R')
nowpos++;
else if(s[i]=='(')
update(nowpos,,,,n);
else if(s[i]==')')
update(nowpos, -,,,n);
else
update(nowpos,,,,n);
///若全区间和不为0,则证明左括号数和右括号数不等
///若全区间最小前缀和不为0,则证明至少有一个右括号没有被左括号对应,
if(lzmi[]<||tree[]!=)
printf("-1 ");
else
printf("%d ",lzma[]);
}
return ;
}

Codeforces Round #603 (Div. 2)E的更多相关文章

  1. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  2. Codeforces Round #603 (Div. 2) E. Editor 线段树

    E. Editor The development of a text editor is a hard problem. You need to implement an extra module ...

  3. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...

  4. Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

    D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...

  5. Codeforces Round #603 (Div. 2) D. Secret Passwords(并查集)

    链接: https://codeforces.com/contest/1263/problem/D 题意: One unknown hacker wants to get the admin's pa ...

  6. Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)

    链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...

  7. Codeforces Round #603 (Div. 2) B. PIN Codes

    链接: https://codeforces.com/contest/1263/problem/B 题意: A PIN code is a string that consists of exactl ...

  8. Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

    链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green an ...

  9. Codeforces Round #603 (Div. 2)F. Economic Difficulties

    F. Economic Difficulties 题目链接: https://codeforces.com/contest/1263/problem/F 题目大意: 两棵树,都有n个叶子节点,一棵树正 ...

  10. Codeforces Round #603 (Div. 2) E. Editor

    E. Editor 题目链接: https://codeforces.com/contest/1263/problem/E 题目大意: 输入一个字符串S1含有‘(’ , ‘)’ , ‘R’ , ‘L’ ...

随机推荐

  1. C++基础--引用的一点补充

    这一篇是对引用的一点补充,内容基本上是来自<C++ primer plus>一书第八章的内容. 前面一篇介绍了引用的一点特点,这里补充一个,将引用用于类对象的时候,有一个体现继承的特征,就 ...

  2. comparable接口 和 comparator接口的特点与区别

    1. Comparator 和 Comparable 相同的地方 他们都是java的一个接口, 并且是用来对自定义的class比较大小的. 什么是自定义class: 如 public class Pe ...

  3. mysql四种事务隔离级别

    mysql事务并发问题 ACID什么的就不啰嗦了.mysql多个事务并发的时候,可能会出现如下问题: 1. 更新丢失 即两个事务同时更新某一条数据,后执行的更新操作会覆盖先执行的更新操作,导致先执行的 ...

  4. IDEA--安装

    1:下载IDEA 官网:http://www.jetbrains.com/idea/download/#section=windows(选择下载.zip) 2:解压 3:破解: 1)在C:\Windo ...

  5. SpringCloud学习之Config分布式配置中心(八)

    统一配置中心概述 如果微服务架构中没有使用统一配置中心时,所存在的问题: 配置文件分散在各个项目里,不方便维护 配置内容安全与权限,实际开发中,开发人员是不知道线上环境的配置的 更新配置后,项目需要重 ...

  6. JetBrains系列-插件

       插件官网:http://plugins.jetbrains.com   注意:网站有时不稳定,会造成打不开,属正常现象或许下一秒就好了,可以选择去git等方式下载 1.安装说明:   打开fil ...

  7. python的debug神器PySnooper

    同事给我推荐了这个调试神器,一直没工夫看,今天看了下. 原文链接: 史上最方便的Python Debug工具|腾讯技术说 体验了下,感觉最好的用法:1.优先逐行调试:2.一些复杂状态处理或者偶现的bu ...

  8. Java学生管理系统(IO版)

    图解: cade: student.java /* * 这是我的学生类 */ public class Student { //学号 private String id; //姓名 private S ...

  9. python3编码问题个人理解

    #coding=utf-8 a = "你" # 这个字符串是Unicode和 a = u“你”等价b = b'\\u4f60' #这个表示b是字节串(如果需要显示b的值则 prin ...

  10. [CISCN2019 华北赛区 Day2 Web1]Hack World

    知识点:题目已经告知列名和表明为flag,接下来利用ascii和substr函数即可进行bool盲注 eg: id=(ascii(substr((select(flag)from(flag)),1,1 ...