Codeforces Round #603 (Div. 2)E
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- 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, ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green an ...
- Codeforces Round #603 (Div. 2)F. Economic Difficulties
F. Economic Difficulties 题目链接: https://codeforces.com/contest/1263/problem/F 题目大意: 两棵树,都有n个叶子节点,一棵树正 ...
- Codeforces Round #603 (Div. 2) E. Editor
E. Editor 题目链接: https://codeforces.com/contest/1263/problem/E 题目大意: 输入一个字符串S1含有‘(’ , ‘)’ , ‘R’ , ‘L’ ...
随机推荐
- Python之日志处理(logging模块)转载
本人主要做一个知识的归类与记录,如是转载类文章,居首都会备注原链接,尊重原创者,谢谢! 此文转载原链接:https://www.cnblogs.com/yyds/p/6901864.html 本节内容 ...
- 刷题31. Next Permutation
一.题目说明 题目是31. Next Permutation,英文太差看不懂,翻译了一下.才知道是求字典顺序下的下一个排列,不允许使用额外空间.题目难度是Medium! 二.我的实现 首先要进一步理解 ...
- Cookie简单介绍
Cookie 饼干. 其实是一份小数据, 是服务器给客户端,并且存储在客户端上的一份小数据 应用场景 自动登录.浏览记录.购物车. 为什么要有这个Cookie http的请求是无状态. 客户端与服务器 ...
- RCE
RCE remote command/code execute 远程系统命令/代码执行 系统从设计上需要给用户提供指定的远程命令操作的接口.可以测试一下自动运维平台. 在PHP中,使用system.e ...
- 新iPhone要推出双卡双待这事是真的吗?
自2007年发布以来,iPhone似乎一直都是"异类"--以自己独特的方式走着一条引领智能手机前进的路!如,在当年遍地按键键盘的年代,iPhone以触摸屏的奇葩姿态引领了新潮流:刚 ...
- Centos7 死循环登录问题
问题:用户名和密码输入正确,登录后屏幕闪一下又回到初始的登录界面.不知道具体什么原因引起的,先记录下不知道是否正确的解决方案,网上找了些相关的方案有的也实现不了,可能这个问题跟装的虚拟机的版本也有关系 ...
- 第32&35章 数据库的安装&存储实力的管理
第32章 数据库的安装IO取决于磁盘的个数和接口带宽 版本安装顺序是从低到高存储架构师 第35章 存储实例的管理ASM配置说白了就是ORACLE自己的,不通过操作系统对磁盘进行管理.fdisk -l查 ...
- python学习笔记-模块和包
模块导入方法 1.import 语句 import module1[,module2[,...moduleN]] 当我们使用import语句的时候,Python解释器是怎么找到对应对文件对呢?答案是解 ...
- paddle(一)
一.概述 一个机器学习的框架,提供了深度学习需要的神经网络,激活函数等主要功能. 基础概念 Program 一次模型训练就是一个program,通过执行器执行,默认环境下是执行fluid.defaul ...
- 可塑性|Exosomes
五流解释 肿瘤发源于不同组织如果不从各种组织出发,则不能有正确的解决方法. Hallmarks of cancer LncRNAs操作流 Exosomes ,它的基本故事是平衡流,但是具体内涵是操作流 ...