#P5067. [Ynoi Easy Round 2014] 长存不灭的过去、逐渐消逝的未来
[Ynoi Easy Round 2014] 长存不灭的过去、逐渐消逝的未来
Description
Chtholly defines a term as a string formed by concatenating several () digits () (for example, 123 and 000 are valid terms, while ** *-1 +5 are invalid terms). A valid expression can be:
- A term (e.g.
233). - Two expressions connected by
+ - *(e.g.2*3+5*5,6-6*6). - An expression with a pair of parentheses added to its left and right (e.g. (
2*3*3)).
Note: the empty string is not a valid expression.
Initially, you are given a string of length . Then operations are given. There are two types of operations:
1 x y: change the character at position to .2 l r: query the value of the substring as an expression modulo . If the substring is not a valid expression, the result is .
Input Format
The first line contains two integers .
The second line contains a string of length .
The next lines each contain 1 x y or 2 l r, representing the two types of operations.
Output Format
For every operation of type 2, output one line containing one integer, which is the answer.
5 12
2*(3)
2 1 1
2 4 4
2 1 5
1 3 2
2 1 5
2 1 4
2 1 3
2 2 3
1 1 (
1 2 5
1 3 +
2 1 5
2
3
6
-1
46
4
-1
8
Hint
Idea: mcfx, Solution: mcfx, Code: mcfx, Data: mcfx.
Constraints: , , .
The character set is 0 1 2 3 4 5 6 7 8 9 + - * ( ).
If we treat ( as , ) as , and other characters as , then it is guaranteed that at any moment, for any prefix of the string, the absolute value of the prefix sum is at most .
Translated by ChatGPT 5
京公网安备 11011102002149号