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. MyBatis的初始化过程。

    对于任何框架而言,在使用前都要进行一系列的初始化,MyBatis也不例外.本章将通过以下几点详细介绍MyBatis的初始化过程. 1.MyBatis的初始化做了什么 2. MyBatis基于XML配置 ...

  2. BZOJ 3442 学习小组

    题解: 神建图 普通的二分图费用流建完后 添加学生x->t 容量为k-1的边 表示尽量让x参加一个活动,剩下的k-1次机会可以不参加 #include<iostream> #incl ...

  3. 《新标准C++程序设计》1.7-1.10(C++学习笔记2)

    1.内联函数(inline关键字) eg.inline int Max(int a,int b) { if(a>b) return a; return b; } 当编译器处理调用内联函数的语句时 ...

  4. Javascript声明和使用变量

    1.1变量的声明 要在程序中使用变量,就必须从声明变量学起,因为Javascript语法与我们基础的其他程序语言声明变量的方法略有不同,但是Javascript语法的变量应用非常强大,使用也非常简单. ...

  5. CentOS 7.3 下部署基于 Node.js的微信小程序商城

    本文档为微信小程序商城NideShop项目的安装部署教程,欢迎star NideShop商城api服务:https://github.com/tumobi/nideshop NideShop微信小程序 ...

  6. VUE- 访问服务器端数据 Vue-resource

    VUE- 访问服务器端数据 Vue-resource 1. 安装 vue-resource cnpm install vue-resource --save 安装完毕后,在main.js中导入,如下所 ...

  7. 2014_csu选拔1_B

    Description Here is no naked girl nor naked runners, but a naked problem: you are to find the K-th s ...

  8. HDU 1298 T9 字典树+DFS

    必须要批评下自己了,首先就是这个题目的迟疑不定,去年做字典树的时候就碰到这个题目了,当时没什么好的想法,就暂时搁置了,其实想法应该有很多,只是居然没想到. 同样都是对单词进行建树,并插入可能值,但是拨 ...

  9. mysql自关联和多表连接查询

    自关联操作         多表连接查询  inner  join 内查询   left  join  左查询   right  join  右查询                          ...

  10. java后台开发细节记录

    1.  ResultMap是程序员控制SQL查询结果和实体类的映射关系,而不是sql语句中字段的重命名,所以在sql语句中还是要按照原来字段的格式进行书写.