题意: 给出一串括号 给出一些询问,问某个区间[l,r]内的能合法匹配的括号数有多少个 分析: 我们能够实现处理两个数组 sum[i] 1....i中已经能匹配的右括号的数目 left[i] 1....i中还不能匹配的左括号数目 这两个数组能够非常easy的扫描一遍动态维护得出来 我们能够先求前缀和,即 1...m中有多少能匹配的右括号sum[m] 则,我们能够得到sum[r]-sum[l-1],区间[l,r]内能合法匹配的右括号 可是这些右括号的匹配包含了和[1,l-1]中的左括号的匹配 所以…
C. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(…
题意:给出一个括号序列,要求维护两种操作: 1.将第x位上的括号取反 2.查询当前整个括号序列是否匹配 n<=3e4 思路:线段树维护区间内没有匹配的左右括号数量 pushup时t[p].r=t[rs].r+t[ls].r-min(t[ls].l,t[rs].r) 不知道这个式子怎么推出来的,但在四种情况下它都成立 #include<cstdio> #include<cstring> #include<string> #include<cmath> #…
[题目链接] http://codeforces.com/problemset/problem/380/C [题目大意] 给出一个括号序列,求区间内左右括号匹配的个数. [题解] 我们发现对于每个右括号,其匹配的左括号是固定的, 我们保存每个右括号匹配的左括号位置, 对区间询问进行线扫描,将扫描的区间右端点及其之前所有的右括号对应的左括号位置做标记, 只要查询询问区间的标记个数就是答案,这个可以用树状数组维护. [代码] #include <cstdio> #include <algor…
题目链接:http://codeforces.com/contest/381/problem/E  E. Sereja and Brackets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a…
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in other words, a string s* of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is describe…
CodeForces - 315B Sereja and Array Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going…
Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in other words, a string s* of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is describe…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 15422   Accepted: 7684 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year wa…
题目链接 给一个括号序列, 两种操作. 一种将某个位置的括号变反(左变右, 右变左), 第二种是询问这个括号序列是否合法. 线段树, 我们开两个数组lf, rg. 表示某个区间里面, 右边的左括号个数, 和左边的右括号个数. ))(( 这个序列lf和rg就都是2. (())这样的话都是0. 如果合法, 那么lf, rg都等于0. #include <iostream> #include <vector> #include <cstdio> #include <cs…