Topic 2: The time limit of Carp flag in the exhibition resort:10000msSingle Point time limit:1000msMemory Limit:256MB
Describe
Yanshou County North listed "North City Park Exhibition Resort", is one of the three major cherry blossom Mutsu. Every year from mid-April to early May, there will be a grand memorial ceremony. In addition to the cherry blossom trails, you can take the sightseeing wagon Xu Xing, and the CARP flag across the North River, along with the local special borrowing strategy to worship the ancestors and the North Ghost Sword Dance.
Let's say we use a parenthesis string containing ' (', ') ' to distinguish the direction of each side of the CARP flag. A sequence of parentheses is called legal when and only if two conditions are met: first, for the entire sequence, the number of opening brackets equals the closing parenthesis; for any prefix, the number of opening brackets is not less than the number of closing parentheses. Island Niang want to know, for a string of parentheses, how many substrings are legal, you can help her.
Input
The input data is only one row, containing a length of n (1?≤? n ?? ≤?106) of the parentheses string.
Output
Outputs a row that represents the number of valid parentheses substrings.
-
-
Sample input
-
-
(()())
-
-
Sample output
-
-
4
Understand test instructions understand for half a day.
For any prefix, the number of opening brackets is not less than the number of closing brackets.
The meaning of this sentence is that the current string as the prefix of the other strings must satisfy the number of opening parentheses not less than the number of closing parentheses NND: Do I have a bad language? I've been reading it.
Title 2: Carp flag at the resort (Hihocoder Challenge)