AT_abc477_d.Masking Tape

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are NN squares arranged in a horizontal row, numbered square 11 to square NN 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 QQ 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 XX, 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 CC.

Find the color of each square after processing all queries (regardless of whether a tile is placed on it).

有 NN 个正方形水平排列成一行,从左到右依次编号为正方形 11 至正方形 NN。颜色用小写英文字母表示。

初始时,每个正方形的颜色均为 a,且没有任何方块放置在任何正方形上。

给定 QQ 个查询,请按顺序处理它们。每个查询属于以下两种类型之一:

  • 1 X :若正方形 XX 上未放置方块,则在其上放置一个方块;若已放置方块,则将其移除。

  • 2 C :将所有未放置方块的正方形的颜色更改为 CC。

请输出处理完所有查询后,每个正方形的颜色(无论其上是否放置了方块)。

输入格式

The input is given from Standard Input in the following format:

NN QQ
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

Each query queryi (1≤i≤Q)\mathrm{query}_i ~ (1 \le i \le Q) is given in the form

11 XX

or

22 CC

输入从标准输入中按以下格式给出:

NN QQ
query1\mathrm{query}_1
⋮\vdots
queryQ\mathrm{query}_Q

每个查询 queryi (1≤i≤Q)\mathrm{query}_i ~ (1 \le i \le Q) 的格式为

11 XX

或

22 CC

输出格式

Output the final colors of the squares as a string of length NN, concatenated from left to right.

以长度为 NN 的字符串形式输出方格的最终颜色,从左到右依次连接。

输入输出样例

  • 输入#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 11-st query places a tile on square 22. The state becomes aaa and .#..
  • Processing the 22-nd query changes the color of the squares without tiles to b. The state becomes bab and .#..
  • Processing the 33-rd query places a tile on square 11. The state becomes bab and ##..
  • Processing the 44-th query removes the tile on square 22. The state becomes bab and #...
  • Processing the 55-th query changes the color of the squares without tiles to c. The state becomes bcc and #...

Thus, output bcc. A tile remains placed on square 11, but even in that case, output the color of the square.

Constraints

  • 1≤N,Q≤3×1051 \le N,Q \le 3\times 10^5
  • Each query is of type 11 or type 22.
  • In type-11 queries, XX is an integer satisfying 1≤X≤N1 \le X \le N.
  • In type-22 queries, CC is a single lowercase English letter.

样例 1 解释:
我们将瓷砖的放置状态表示为一个字符串,该字符串通过从左到右拼接得到:若某方格上放置了瓷砖,则对应字符为 #;否则为 .。

各查询依次改变方格的颜色及瓷砖的放置状态,初始状态为 aaa 和 ...。

  • 执行第 11 个查询,在第 22 个方格上放置一块瓷砖。状态变为 aaa 和 .#.。
  • 执行第 22 个查询,将所有未放置瓷砖的方格颜色改为 b。状态变为 bab 和 .#.。
  • 执行第 33 个查询,在第 11 个方格上放置一块瓷砖。状态变为 bab 和 ##.。
  • 执行第 44 个查询,移除第 22 个方格上的瓷砖。状态变为 bab 和 #..。
  • 执行第 55 个查询,将所有未放置瓷砖的方格颜色改为 c。状态变为 bcc 和 #..。

因此,输出 bcc。尽管第 11 个方格上仍放置着瓷砖,但输出的仍是该方格的颜色。

约束条件

  • 1≤N,Q≤3×1051 \le N,Q \le 3\times 10^5
  • 每个查询为类型 11 或类型 22。
  • 在类型 11 的查询中,XX 是满足 1≤X≤N1 \le X \le N 的整数。
  • 在类型 22 的查询中,CC 是一个小写英文字母。

输入解题思路,AI测评打分。不知道怎么写?

首页