QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#1194. 括号编辑器

统计

你正在使用一个奇怪的文本编辑器,该编辑器仅处理由左括号和右括号组成的文本。编辑器接受以下三个按键作为编辑命令来修改其中的文本:

  • ‘(’:在文本末尾追加一个左括号‘(’。
  • ‘)’:在文本末尾追加一个右括号‘)’。
  • ‘-’:删除文本的最后一个字符。

平衡字符串定义如下:

  • ()
  • (X),其中 X 是一个平衡字符串
  • XY,其中 X 和 Y 都是平衡字符串

最初,编辑器中的文本为空。你需要计算在每次输入编辑命令后,编辑器中当前文本包含的平衡子串的数量。注意,对于出现两次或多次的相同平衡子串,它们的每次出现都应分别计数。同时请注意,当某些平衡子串位于另一个平衡子串内部时,内部和外部的平衡子串都应被计入。

输入格式

输入包含一个测试用例,由一行字符组成,每个字符都是一个编辑命令,即‘(’、‘)’或‘-’。字符总数不超过 $2 \cdot 10^5$。它们代表了对编辑器的按键输入序列。

保证在文本为空时不会出现‘-’命令。

输出格式

在应用每个按键输入命令后,输出编辑器中当前文本包含的平衡子串数量,每行输出一个数字。因此,输出的行数应与输入行中的字符数相同。

样例

样例输入 1

(()())---)

样例输出 1

0
0
1
1
3
4
3
1
1
2

样例输入 2

()--()()----)(()()))

样例输出 2

0
1
0
0
0
1
1
3
1
1
0
0
0
0
0
1
1
3
4
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.