#P3797. 妖梦斩木棒
妖梦斩木棒
Description
One day, Youmu was practicing swordsmanship. There was an extremely long wooden rod on the ground, and Youmu cut it into equal segments. Now this rod can be regarded as composed of three kinds of small segments: the middle segments are stumps cut on both sides, denoted by X; the leftmost segment and the rightmost segment each have a rounded end, denoted by ( and ) respectively.
After eating her fill and feeling bored, Yuyuko decided to play a prank on Youmu. She brought many small wooden segments of these three types to replace part of the segments Youmu had cut, and then asked Youmu some questions.
These operations are described as follows:
1 x CReplace the -th small segment with type , where is one ofX,(,).2 l rQuery how many complete rods are in the interval (inclusive).
A complete rod must have ( on the left end and ) on the right end, and between them there may be zero or more X only.
Although Youmu can count the answers to these questions, Yuyuko thinks she answers too slowly. Can you teach Youmu a faster method?
Input Format
The first line contains two integers , representing that there are segments and operations.
The initial shape of the rod is (XXXX...XXXX).
Then follow lines, each describing one operation in one of the following forms, separated by spaces:
- Type 1:
1 x C— an integer and a character . - Type 2:
2 l r— two integers .
The meanings are as described above.
Output Format
For each type 2 operation, output one line with one integer, representing the answer to that query.
4 4
2 1 4
2 2 4
1 2 (
2 2 4
1
0
1
Hint
For 30% of the testdata, .
For 100% of the testdata, .
by-orangebird.
Translated by ChatGPT 5
京公网安备 11011102002149号