306867: CF1263E. Editor
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Editor
题意翻译
### 题意 您要设计一个只有一行的打字机,这一行的长度是无限大,一开始可以认为每个字符都是空。您的打字机有一个光标只指向一个字符,一开始指向最左侧的字符。 使用者有三种操作: - **L** 将光标向左移一格(当光标已经在最左侧时,忽略这次操作) - **R** 将光标向右移一格 - **一个小写字符或者'(',')'** 将当前字符替换为给定字符 您需要在每次操作后,判断这一行是否是合法括号序列(例如 ``(ahakioi)`` 就是合法的,``(ige))(tscore`` 就是非法的),不是输出 ``-1``,否则输出最多嵌套数(例如 ``()(())()()`` 的最多嵌套数是 2,``(()(()())())(())`` 的最多嵌套数是 3)。 ### 输入 / 输出格式 第一行输入一个正整数 $n(1\le n\le 10^6)$ 表示操作数 接下来一行一个长度为 $n$ 的字符串,只含 `L,R,(,)`,小写字母,表示操作序列,第 $i$ 个字符表示第 $i$ 次操作。 输出 $n$ 个正整数表示每次操作后的结果。 ### 样例解释 ```plain 1. ( 2. ( 3. (a 4. (a 5. (ab 6. (ab 7. (ab) 8. (ab) 9. (a)) 10. (a)) 11. (()) ```题目描述
The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters). Thus, it points to an index character. The user can move the cursor left or right one position. If the cursor is already at the first (leftmost) position, then it does not move left. Initially, the cursor is in the first (leftmost) character. Also, the user can write a letter or brackets (either (, or )) to the position that the cursor is currently pointing at. A new character always overwrites the old value at that position. Your editor must check, whether the current line is the correct text. Text is correct if the brackets in them form the correct bracket sequence. Formally, correct text (CT) must satisfy the following rules: - any line without brackets is CT (the line can contain whitespaces); - If the first character of the string — is (, the last — is ), and all the rest form a CT, then the whole line is a CT; - two consecutively written CT is also CT. Examples of correct texts: hello(codeforces), round, ((i)(write))edi(tor)s, ( me). Examples of incorrect texts: hello)oops(, round), ((me). The user uses special commands to work with your editor. Each command has its symbol, which must be written to execute this command. The correspondence of commands and characters is as follows: - L — move the cursor one character to the left (remains in place if it already points to the first character); - R — move the cursor one character to the right; - any lowercase Latin letter or bracket (( or )) — write the entered character to the position where the cursor is now. For a complete understanding, take a look at the first example and its illustrations in the note below. You are given a string containing the characters that the user entered. For the brackets coloring module's work, after each command you need to: - check if the current text in the editor is a correct text; - if it is, print the least number of colors that required, to color all brackets. If two pairs of brackets are nested (the first in the second or vice versa), then these pairs of brackets should be painted in different colors. If two pairs of brackets are not nested, then they can be painted in different or the same colors. For example, for the bracket sequence ()(())()() the least number of colors is $ 2 $ , and for the bracket sequence (()(()())())(()) — is $ 3 $ . Write a program that prints the minimal number of colors after processing each command.输入输出格式
输入格式
The first line contains an integer $ n $ ( $ 1 \le n \le 10^6 $ ) — the number of commands. The second line contains $ s $ — a sequence of commands. The string $ s $ consists of $ n $ characters. It is guaranteed that all characters in a string are valid commands.
输出格式
In a single line print $ n $ integers, where the $ i $ -th number is: - $ -1 $ if the line received after processing the first $ i $ commands is not valid text, - the minimal number of colors in the case of the correct text.
输入输出样例
输入样例 #1
11
(RaRbR)L)L(
输出样例 #1
-1 -1 -1 -1 -1 -1 1 1 -1 -1 2
输入样例 #2
11
(R)R(R)Ra)c
输出样例 #2
-1 -1 1 1 -1 -1 1 1 1 -1 1