#P15456. [JOI 2026 SemiFinal] 奇妙な機械 / Strange Machine
[JOI 2026 SemiFinal] 奇妙な機械 / Strange Machine
Problem Description
You have tiles, numbered from to . Each tile has a front side and a back side, and each side is colored either black or white. Here, black is represented by the character 'B', and white is represented by the character 'W'. For tile (), its front-side color is given by the -th character of the string , and its back-side color is given by the -th character of the string .
Uzbekistan is famous for its historical buildings decorated with tiles. After visiting mosques and madrasas in Uzbekistan, you were fascinated by these beautiful buildings and bought a strange machine. This machine has a platform on the left and a platform on the right. By placing one tile on each platform, you can exchange these two tiles for one new tile. Let the tile placed on the left platform be , and the tile placed on the right platform be . The new tile obtained from and satisfies the following:
- The front-side color of : it is black if the back-side color of is the same as the front-side color of ; otherwise, it is white.
- The back-side color of : it is black if the front-side color of is the same as the back-side color of ; otherwise, it is white.
You plan to use these tiles and the strange machine to do the following activities over days. On day (), the activity is either type 1 or type 2:
- Type 1: Change the front-side color of tile to the color represented by the character , and change the back-side color of tile to the color represented by the character . Here are
'B'or'W'. - Type 2: Arrange tiles in this order into a row from left to right. For this row, you may perform the following operation any number of times (from up to times), and then determine whether it is possible to make the number of tiles whose front side is white in the row equal to exactly :
- Choose two adjacent tiles in the row and remove them from the row. Put the tile that was originally on the left onto the left platform of the machine, and the one originally on the right onto the right platform. Exchange them for one new tile, and then insert the new tile back into the position where the two tiles were.
Given the initial tile information and the activities for each day, write a program to output the answer for all type 2 activities.
Input Format
Input is given from standard input in the following format:
(Query 1)
(Query 2)
(Query )
Each (Query ) () contains several space-separated integers or characters. The first value is an integer or , denoted by , and the rest of the line is one of the following:
- If , then it is followed by an integer and two characters in this order. This means the activity on day is type 1: change the front-side color of tile to the color represented by , and change the back-side color to the color represented by . Here are
BorW. - If , then it is followed by three integers in this order. This means the activity on day is type 2: arrange tiles in order into a row from left to right, and determine whether it is possible (using the operations) to make the number of tiles whose front side is white in the row exactly .
Output Format
For all such that (), output one line per query in increasing order of : output Yes if it is possible to make the number of tiles whose front side is white in the row exactly , and output No otherwise.
4
WBWB
BWBB
5
2 3 4 1
2 1 2 0
1 3 B B
2 3 4 2
2 2 4 1
Yes
Yes
No
Yes
6
BWBWWB
WBWBBB
8
2 1 3 2
2 2 6 0
2 1 5 3
2 3 3 0
2 3 4 1
2 5 6 2
2 2 6 4
2 1 4 2
No
Yes
Yes
Yes
Yes
No
No
Yes
Hint
Sample Explanation 1
- Day 1: Arrange tiles in this order into a row from left to right. If you do not perform any operation, only tile has a white front side, so it is possible to make the number of tiles with a white front side exactly . Therefore output
Yes. - Day 2: Arrange tiles in this order into a row. If you choose tiles and and perform the operation once, the resulting row contains one tile whose front and back sides are both black, so it is possible to make the number of tiles with a white front side exactly . Therefore output
Yes. - Day 3: Change both the front and back sides of tile to black.
- Day 4: Arrange tiles into a row. It can be proven that it is impossible to make the number of tiles with a white front side exactly by using the operations. Therefore output
No. - Day 5: Arrange tiles into a row. If you first choose tiles and and perform the operation once, the row will contain two tiles: tile on the left and a new tile (whose front and back sides are both black) on the right. Then choose these two tiles and perform the operation once more; the row will contain one tile whose front side is white and back side is black, so it is possible to make the number of tiles with a white front side exactly . Therefore output
Yes.
This sample input satisfies the constraints of subtasks .
Constraints
- is a string of length consisting of
BandW - is a string of length consisting of
BandW - is or ()
- If , then ()
- If , then is
'B'or'W'() - If , then is
'B'or'W'() - If , then ()
- If , then ()
- are all integers.
Subtasks
- (6 points) .
- (10 points) , and ().
- (9 points) , and ().
- (8 points) , and ().
- (23 points) , .
- (14 points) , .
- (30 points) No additional constraints.
Translated by DeepSeek.
Translated by ChatGPT 5