当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
For the sake of simplicity, only the following subset of Python syntax is considered:
PLAIN_TEXT
:
[^"()\[\]{}]+
STRING
:
\"[^"]*\"
text:
(empty)
text
| PLAIN_TEXT
text
| STRING
text
|
bracket_enclosed_text
bracket_enclosed_text: (
text )
| [
text ]
| {
text }
From the syntax some terms are defined as follows:
String: a sequence delimited by quotes ("
) of characters other than quotes, possibly including new-lines.
Examples:
"a(bc"
"a
bc)"
"usage: foo [bar]
this help information
is
totally
useless"
(Python actually """
for such strings, but let’s accept the modification just for this problem.)
Bracket-enclosed text: a sequence of characters other than brackets or quotes enclosed by matched pairs of brackets.
Example:
(1)
{a->[foo.bar(
"a[",b,c
)]}
Logical new-line: a new-line character that is not part of a string or bracket-enclosed text
Physical line: a maximal sequence of characters other than new-line characters
Examples:
def a(b)
# physical line 1
# physical line 2
foo.bar(
# physical line 3
"a[",b)
# physical line 4
"blah blah,
# physical line 5
blah"
Logical line: a maximal sequence of characters other than logical new-lines
Examples:
def a(b)
# logical line 1
# logical line 2
foo.bar(
# logical line 2
"a[",b)
# logical line 3
"blah blah,
# logical line 3
blah"
Valid/invalid program: a program without/with mismatched quotes or brackets that are not part of any strings
Examples:
def a(b
"blah
Given a program, you are to implement the following primitive operations:
The given program appears first in the input followed by a line with a single #
. Then come the operation descriptions. Each operation is described in the format c
a
b, where c is a character, a a physical line number and b a column number. Both physical line and column numbers are counted starting from 1. If c is ?
, the operation will be query(a, b), otherwise it will be modify(a, b, c). The program can be invalid while being edited, but whenever a query operation is demanded, it will always be valid. A modify operation will neither remove existing spaces and new-lines in the program nor introduce new ones. Tabs are not present in the input.
The program contains up to 106 characters (including new-lines) and 105 physical lines each consisting of up to 80 characters. And there will be at most 105 operations.
For each query operation, output a line containing the logical line number.
aaa (bb ccc dd) fff # ? 1 1 ? 5 1 b 2 1 d 4 3 ? 5 1 " 1 3 " 5 2 ? 5 1 a 1 3 f 5 2 ? 5 1
1 3 5 1 5
时间上限 | 内存上限 |
2000 | 131072 |