CF1625E1.Cats on the Upgrade (easy version)
省选/NOI-
通过率:0%
时间限制:6.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The only difference between the easy and the hard versions are removal queries, they are present only in the hard version.
"Interplanetary Software, Inc." together with "Robots of Cydonia, Ltd." has developed and released robot cats. These electronic pets can meow, catch mice and entertain the owner in various ways.
The developers from "Interplanetary Software, Inc." have recently decided to release a software update for these robots. After the update, the cats must solve the problems about bracket sequences. One of the problems is described below.

First, we need to learn a bit of bracket sequence theory. Consider the strings that contain characters "(", ")" and ".". Call a string regular bracket sequence (RBS), if it can be transformed to an empty string by one or more operations of removing either single "." characters, or a continuous substring "()". For instance, the string "(()(.))" is an RBS, as it can be transformed to an empty string with the following sequence of removals:
"(()(.))" → "(()())" → "(())" → "()" → "".
We got an empty string, so the initial string was an RBS. At the same time, the string ")(" is not an RBS, as it is not possible to apply such removal operations to it.
An RBS is simple if this RBS is not empty, doesn't start with ".", and doesn't end with ".".
Denote the substring of the string s as its sequential subsegment. In particular, s[l…r]=slsl+1…sr, where si is the i-th character of the string s.
Now, move on to the problem statement itself. You are given a string s, initially consisting of characters "(" and ")". You need to answer the queries of the following kind.
Given two indices, l and r (1≤l<r≤n), and it's guaranteed that the substring s[l…r] is a simple RBS. You need to find the number of substrings in s[l…r] such that they are simple RBS. In other words, find the number of index pairs i, j such that l≤i<j≤r and s[i…j] is a simple RBS.
You are an employee in "Interplanetary Software, Inc." and you were given the task to teach the cats to solve the problem above, after the update.
Note that the "." character cannot appear in the string in this version of the problem. It is only needed for the hard version.
这是该问题的简单版本。简单版本与困难版本的唯一区别在于“删除查询”:此类查询仅出现在困难版本中。
“星际软件公司(Interplanetary Software, Inc.)”联合“赛东尼亚机器人有限公司(Robots of Cydonia, Ltd.)”共同研发并发布了机器人猫。这些电子宠物能够喵喵叫、抓老鼠,并以多种方式为主人提供娱乐。
“星际软件公司”的开发人员最近决定为这些机器人发布一次软件更新。更新之后,机器人猫必须能够求解关于括号序列的问题。其中一道问题如下所述。

首先,我们需要了解一些括号序列理论。考虑由字符 "(", ")" 和 "." 组成的字符串。若一个字符串可通过若干次操作(每次操作可移除单个 "." 字符,或移除一个连续子串 "()")变为空字符串,则称其为正则括号序列(Regular Bracket Sequence, RBS)。例如,字符串 "(()(.))" 是一个 RBS,因为它可通过如下一系列移除操作变为空字符串:
"(()(.))" → "(()())" → "(())" → "()" → ""。
我们最终得到了空字符串,因此初始字符串是一个 RBS。而字符串 ")(" 则不是 RBS,因为无法对其应用上述移除操作。
若一个 RBS 非空、不以 "." 开头、也不以 "." 结尾,则称其为简单 RBS(simple RBS)。
记字符串 s 的子串为其连续子段。特别地,s[l…r]=slsl+1…sr,其中 si 表示字符串 s 的第 i 个字符。
现在进入问题本身。给定一个初始仅由字符 "(" 和 ")" 构成的字符串 s。你需要回答如下类型的查询:
给定两个下标 l 和 r(满足 1≤l<r≤n),且保证子串 s[l…r] 是一个简单 RBS。你需要计算 s[l…r] 中有多少个子串是简单 RBS。换言之,即求满足 l≤i<j≤r 且 s[i…j] 是简单 RBS 的下标对 (i,j) 的数量。
你身为“星际软件公司”的一名员工,被委派了在此次更新后教会机器人猫解决上述问题的任务。
注意:在本题(简单版本)中,字符串中不会出现 "." 字符;该字符仅在困难版本中使用。
输入格式
The first line contains two integers n and q (2≤n≤3⋅105, 1≤q≤3⋅105), the length of the string, and the number of queries.
The second line contains the string s, consisting of n characters "(" and ")".
Each of the following q lines contains three integers t, l and r (t=2, 1≤l<r≤n), the queries you need to answer. It is guaranteed that all the queries are valid and correspond to the problem statements. Note that t is unused and always equal to two in this problem. It is required for the hard version of the problem.
第一行包含两个整数 n 和 q(2≤n≤3⋅105,1≤q≤3⋅105),分别表示字符串的长度和查询次数。
第二行包含字符串 s,由 n 个字符组成,每个字符为 ( 或 )。
接下来的 q 行每行包含三个整数 t、l 和 r(t=2,1≤l<r≤n),表示你需要回答的查询。保证所有查询均合法且符合题目描述。注意,本题中 t 未被使用,且恒等于 2;该参数是为本题的困难版本所预留的。
输出格式
For each query, print a single integer in a separate line, the number of substrings that are simple RBS. The answers must be printed in the same order as the queries are specified in the input.
对于每个查询,在单独的一行中输出一个整数,表示是简单 RBS 的子串数量。答案的输出顺序必须与输入中查询的顺序一致。
输入输出样例
输入#1
9 4 )(()())() 2 3 6 2 2 7 2 8 9 2 2 9
输出#1
3 4 1 6
说明/提示
Consider the example test case.
The answer to the first query is 3, as there are three suitable substrings: s[3…6], s[3…4] and s[5…6].
The answer to the second query is 4. The substrings are s[3…6], s[3…4], s[5…6] and s[2…7].
The answer to the third query is 1. The substring is s[8…9].
The answer to the fourth query is 6. The substrings are s[3…6], s[3…4], s[5…6], s[2…7], s[8…9] and s[2…9].
考虑示例测试用例。
第一个查询的答案为 3,因为有三个满足条件的子串:s[3…6]、s[3…4] 和 s[5…6]。
第二个查询的答案为 4。这些子串是 s[3…6]、s[3…4]、s[5…6] 和 s[2…7]。
第三个查询的答案为 1。该子串为 s[8…9]。
第四个查询的答案为 6。这些子串是 s[3…6]、s[3…4]、s[5…6]、s[2…7]、s[8…9] 和 s[2…9]。
输入解题思路,AI测评打分。不知道怎么写?