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. 洛谷 P2516 [HAOI2010]最长公共子序列

    题目传送门 解题思路: 第一问要求最长公共子序列,直接套模板就好了. 第二问要求数量,ans[i][j]表示第一个字符串前i个字符,第二个字符串前j个字符的最长公共子序列的数量 如果f[i][j]是由 ...

  2. IBGP(内部BGP)的对等体组(命令解析)

    IBGP(内部BGP)对等体组配置解析: ①:创建对等体组. ②:定义对等体组策略,指定邻居路由器及所在的AS. ③:定义,更新源. ④:(若边界)定义自己下一跳. ⑤:加入对等体组. IBGP(内部 ...

  3. 七、SAP中输出当前日期

    一.在Sap中输出当前日期的函数是sy-datum,代码如下: 二.输出效果如下

  4. 如何通过C语言获取主机WLAN下的IPv4地址,MAC地址

    #include "stdio.h" #include "windows.h" void GetHostWLAN_IPv4_AND_MAC(char IPv4[ ...

  5. OI常用模板

    long long qpow(long long a,long long b,int mod) { ; while (b) { ) res=res*a%mod; a=a*a%mod; b>> ...

  6. Maven - 工作原理

    章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Maven – 构建生命周期.阶段 ...

  7. 根据pdf文件获取标题等信息

    根据 kdd2019的 pdf文件, 生成索引文档. 代码如下: for fname in ` ls pdfs/*.pdf`; do title=$(mdls -name kMDItemTitle - ...

  8. Odd sum (对本菜鸡来说是个极坑题)

    https://codeforces.com/problemset/problem/797/B time limit per test 1 second memory limit per test 2 ...

  9. Linux 常用命令全拼

    pwd: print work directory 打印当前目录 显示出当前工作目录的绝对路径 ps: process status(进程状态,类似于windows的任务管理器) 常用参数:-auxf ...

  10. Django模型基础(三)——关系表的数据操作

    模型之间可以有三种表关系,即一对一,一对多和多对多.表关联之间的数据操作在Django中可以很方便的操作到.在模型中,表关联的字段类型是关联表的实例,而不是字段本身类型.关联字段在数据库中会在其后补上 ...