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’ ...
随机推荐
- 使用dbcp连接mysql
1.创建dbcp.properties 文件 driver=com.mysql.jdbc.Driver url=jdbc:mysql:///zhang username=root password= ...
- SpringAOP切入点的表达式
1. 常用的切入点表达式分为: (1)按类型匹配:within 关键字 (2)按函数匹配:execution (3)按bean的id匹配:bean 2.按类匹配的写法 匹配到具体的类:<aop ...
- mui 横屏 竖屏
在项目中只有某个页面需要横屏 ,其他的都是竖屏展示的. 假设a页面横屏 ,返回之后竖屏 b页面 a+ 将其设置为横屏显示: b+ 将其设置为竖屏显示 但是进入a页面之后再返回b页面时 b页面也会称为横 ...
- jQuery元素的左右移动
1.下载jQuery,并导入:https://blog.csdn.net/weixin_44718300/article/details/88746796 2.代码实现: <!DOCTYPE h ...
- 关于torch.norm函数的笔记
先看一下它的参数: norm(p='fro', dim=None, keepdim=False, dtype=None) p: the order of norm. 一般来说指定 $p = 1, 2$ ...
- Centos 7.4 DNS域名解析
1.安装部署包 yum -y install bind bind-utils bind-chroot 2.启动服务并设置开机自启动 [root@localhost ~]# systemctl star ...
- mysql锁探究和实验
如何保证数据并发访问的一致性.有效性是所有数据库必须解决的一个问题,锁冲突也是影响数据库并发访问性能的一个重要因素.从这个角度来说,锁对数据库而言显得尤其重要,也更加复杂. 表锁和行锁 mysql最显 ...
- Win10 MySQL5.7中文乱码问题
https://blog.csdn.net/hh___56789/article/details/87900923 最好把 utf8 都换成utf8mb4 ,以免以后遇到意想不到的错误.utf8有漏洞 ...
- 69.ORM查询条件:isnull和regex的使用
首先查看数据库中的article表的数据: 定义模型的文件models.py中的示例代码如下: from django.db import models class Category(models.M ...
- hook键盘钩子_非dll
unit Unit1; // download by http://www.codefans.net interface uses Windows, Messages, SysUtils, Class ...