CF380C.Sereja and Brackets
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sereja has a bracket sequence s1,s2,...,sn , or, in other words, a string s of length n , consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers li,ri (1<=li<=ri<=n) . The answer to the i -th query is the length of the maximum correct bracket subsequence of sequence sli,sli+1,...,sri . Help Sereja answer all queries.
You can find the definitions for a subsequence and a correct bracket sequence in the notes.
Sereja 有一个括号序列s1,s2,...,sn ,或者换句话说,一个长度为 n 的字符串 s ,由字符 "(" 和 ")" 组成。
Sereja 需要回答 m 个查询,每个查询由两个整数 li, ri 描述。 li,ri (1<=li<=ri<=n) .第 i 个查询的答案是序列 sli,sli+1,...,sri 的最大正确括号子序列的长度。帮助 Sereja 回答所有问题。
您可以在注释中找到子序列和正确括号序列的定义。
输入格式
The first line contains a sequence of characters s1,s2,...,sn (1<=n<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer m (1<=m<=105) — the number of queries. Each of the next m lines contains a pair of integers. The i -th line contains integers li,ri (1<=li<=ri<=n) — the description of the i -th query.
输入
第一行包含字符 s1,s2,...,sn (1<=n<=106)序列,不含空格。每个字符都是"("或")"。第二行包含整数 m (1<=m<=105) - 查询次数。接下来的每行 m 都包含一对整数。第 i 行包含整数 li,ri (1<=li<=ri<=n) - i 次查询的描述。
输出格式
Print the answer to each question on a single line. Print the answers in the order they go in the input.
输出
将每个问题的答案打印在一行上。按输入的顺序打印答案。
输入输出样例
输入#1
())(())(())( 7 1 1 2 3 1 2 1 12 8 12 5 11 2 10
输出#1
0 0 2 10 4 6 6
说明/提示
A subsequence of length ∣x∣ of string s=s1s2... s∣s∣ (where ∣s∣ is the length of string s ) is string x=sk1sk2... sk∣x∣ (1<=k1<k2<...<k∣x∣<=∣s∣) .
A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
For the third query required sequence will be «()».
For the fourth query required sequence will be «()(())(())».
注
字符串s=s1s2... s∣s∣ (其中 |s| 是字符串 s 的长度)的长度为 |x| 的 子序列是字符串x=sk1sk2... sk∣x∣ (1<=k1<k2<...<k∣x∣<=∣s∣)。
正确的括号序列是指可以通过在字符串的字符之间插入字符"1"和"+"来转换为正确的重音表达式的括号序列。例如,括号序列"()()", "(())" 是正确的(得到的表达式为"(1)+(1)"、"((1+1)+1)"),而")("和"("则不正确。
第三个查询所需的序列将是"()"。
第四个查询的必填序列是"()()()()) "。