AT_abc477_d.Masking Tape
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N squares arranged in a horizontal row, numbered square 1 to square N from left to right. Colors are represented by lowercase English letters.
Initially, the color of every square is a, and nothing is placed on any square.
You are given Q queries; process them in the given order. Each query is of one of the following two types:
-
1 X: If no tile is placed on square X, place a tile on it; if a tile is placed on it, remove it. -
2 C: Change the color of every square on which no tile is placed to C.
Find the color of each square after processing all queries (regardless of whether a tile is placed on it).
有 N 个正方形水平排列成一行,从左到右依次编号为正方形 1 至正方形 N。颜色用小写英文字母表示。
初始时,每个正方形的颜色均为 a,且没有任何方块放置在任何正方形上。
给定 Q 个查询,请按顺序处理它们。每个查询属于以下两种类型之一:
-
1 X:若正方形 X 上未放置方块,则在其上放置一个方块;若已放置方块,则将其移除。 -
2 C:将所有未放置方块的正方形的颜色更改为 C。
请输出处理完所有查询后,每个正方形的颜色(无论其上是否放置了方块)。
输入格式
The input is given from Standard Input in the following format:
N Q
query1
⋮
queryQ
Each query queryi (1≤i≤Q) is given in the form
1 X
or
2 C
输入从标准输入中按以下格式给出:
N Q
query1
⋮
queryQ
每个查询 queryi (1≤i≤Q) 的格式为
1 X
或
2 C
输出格式
Output the final colors of the squares as a string of length N, concatenated from left to right.
以长度为 N 的字符串形式输出方格的最终颜色,从左到右依次连接。
输入输出样例
输入#1
3 5 1 2 2 b 1 1 1 2 2 c
输出#1
bcc
输入#2
10 15 1 8 2 m 1 3 1 10 2 q 1 6 1 10 2 d 1 1 2 z 1 9 2 f 1 4 1 7 2 k
输出#2
dkmfkqfazk
说明/提示
Sample 1 Explanation:
We represent the state of tiles as a string formed by concatenating, from left to right, # if a tile is placed and . otherwise.
The queries change the colors of the squares and the state of tiles as follows. The initial state is aaa and ....
- Processing the 1-st query places a tile on square 2. The state becomes
aaaand.#.. - Processing the 2-nd query changes the color of the squares without tiles to
b. The state becomesbaband.#.. - Processing the 3-rd query places a tile on square 1. The state becomes
baband##.. - Processing the 4-th query removes the tile on square 2. The state becomes
baband#... - Processing the 5-th query changes the color of the squares without tiles to
c. The state becomesbccand#...
Thus, output bcc. A tile remains placed on square 1, but even in that case, output the color of the square.
Constraints
- 1≤N,Q≤3×105
- Each query is of type 1 or type 2.
- In type-1 queries, X is an integer satisfying 1≤X≤N.
- In type-2 queries, C is a single lowercase English letter.
样例 1 解释:
我们将瓷砖的放置状态表示为一个字符串,该字符串通过从左到右拼接得到:若某方格上放置了瓷砖,则对应字符为 #;否则为 .。
各查询依次改变方格的颜色及瓷砖的放置状态,初始状态为 aaa 和 ...。
- 执行第 1 个查询,在第 2 个方格上放置一块瓷砖。状态变为
aaa和.#.。 - 执行第 2 个查询,将所有未放置瓷砖的方格颜色改为
b。状态变为bab和.#.。 - 执行第 3 个查询,在第 1 个方格上放置一块瓷砖。状态变为
bab和##.。 - 执行第 4 个查询,移除第 2 个方格上的瓷砖。状态变为
bab和#..。 - 执行第 5 个查询,将所有未放置瓷砖的方格颜色改为
c。状态变为bcc和#..。
因此,输出 bcc。尽管第 1 个方格上仍放置着瓷砖,但输出的仍是该方格的颜色。
约束条件
- 1≤N,Q≤3×105
- 每个查询为类型 1 或类型 2。
- 在类型 1 的查询中,X 是满足 1≤X≤N 的整数。
- 在类型 2 的查询中,C 是一个小写英文字母。
输入解题思路,AI测评打分。不知道怎么写?