UNICORN 编程竞赛 2026(第 477 场 AtCoder Beginner Contest)
D
遮蔽胶带
Masking Tape
AtCoder
⌀ 946
原题
← CE →

遮蔽胶带AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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.

有 $N$ 个方格从左到右排成一行,依次编号为方格 $1$ 到方格 $N$。颜色用小写英文字母表示。AI (CI翻译)

Initially, the color of every square is a, and nothing is placed on any square.

初始时,每个方格的颜色都是 a,且没有任何方格上放置块。AI (CI翻译)

You are given $Q$ queries; process them in the given order. Each query is of one of the following two types:

给定 $Q$ 个询问,请按给定顺序处理。每个询问属于以下两种类型之一:AI (CI翻译)

  • 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$.
  • 1 X:如果方格 $X$ 上没有放置块,则在该方格上放置一个块;如果已经放置了块,则将其移除。
  • 2 C:将所有没有放置块的方格的颜色改为 $C$。
AI (CI翻译)

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

请找出处理完所有询问后每个方格的颜色(无论该方格上是否放置了块)。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \le N,Q \le 3\times 10^5$
  • Each query is of type $1$ or type $2$.
  • In type-$1$ queries, $X$ is an integer satisfying $1 \le X \le N$.
  • In type-$2$ queries, $C$ is a single lowercase English letter.
  • $1 \le N,Q \le 3\times 10^5$
  • 每个询问的类型为 $1$ 或 $2$。
  • 在类型为 $1$ 的询问中,$X$ 是满足 $1 \le X \le N$ 的整数。
  • 在类型为 $2$ 的询问中,$C$ 是一个小写英文字母。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
AI (CI翻译)

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

每个询问 $\mathrm{query}_i ~ (1 \le i \le Q)$ 按以下格式之一给出:AI (CI翻译)

1 X

1 X
AI (CI翻译)

or

或AI (CI翻译)

2 C

2 C
AI (CI翻译)

Output

输出格式

AI (CI翻译)

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

将每个方格最终的颜色从左到右拼接成一个长度为 $N$ 的字符串并输出。AI (CI翻译)

样例

Input #1
3 5
1 2
2 b
1 1
1 2
2 c
Output #1
bcc
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 `aaa` and `.#.`. - Processing the $2$-nd query changes the color of the squares without tiles to `b`. The state becomes `bab` and `.#.`. - Processing the $3$-rd query places a tile on square $1$. The state becomes `bab` and `##.`. - Processing the $4$-th query removes the tile on square $2$. The state becomes `bab` and `#..`. - Processing the $5$-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 $1$, but even in that case, output the color of the square.
Input #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
Output #2
dkmfkqfazk
题目信息
题号
abc477_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。