QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#15606. 弹珠

Statistics

Busy Beaver 将 $N$ 个编号为 $1$ 到 $N$ 的弹珠排成一排,其中第 $i$ 个弹珠上写着一个数字 $p_i \neq i$,并且 $1$ 到 $N$ 中的每个数字在 $p_1, \dots, p_N$ 中恰好出现一次(更正式地, $p$ 是 $1, \dots, N$ 的一个排列,且满足 $p_i \neq i$)。

他想给这些弹珠涂上颜色,使得每个弹珠 $i$ 的颜色都与弹珠 $p_i$ 的颜色不同。然而,他只有三种颜色:红色、绿色和蓝色。请帮助他找到任意一种合法的涂色方案。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 10^4$) —— 测试用例的数量。

每个测试用例的第一行包含一个整数 $N$ ($2 \le N \le 10^5$) —— 弹珠的数量。

每个测试用例的第二行包含 $N$ 个整数 $p_1, p_2, \dots, p_N$ ($1 \le p_i \le N$; $p_i \neq i$) —— 弹珠上的数字。这些数字是数字 $1, \dots, N$ 按某种顺序的一个重新排列。

所有测试用例中 $N$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,输出一个长度为 $N$ 的字符串,其中包含字符 RGB,第 $i$ 个字符表示第 $i$ 个弹珠的颜色(分别代表红、绿、蓝),且满足约束条件。

如果有多个可能的答案,你可以输出其中任意一个。我们已经证明,在这些约束条件下,答案总是存在的。

样例

输入样例 1

5
5
2 1 5 3 4
6
2 1 4 3 6 5
5
2 3 4 5 1
3
3 1 2
4
4 3 2 1

输出样例 1

GBBGR
BGGRRB
RBRBG
RGB
BRGG

说明

在第一个测试用例中,涂色方案 GBBGR 的工作原理如下:

  • 弹珠 1 涂为绿色,上面写着数字 2;弹珠 2 涂为蓝色,因为绿色和蓝色不同,所以满足约束条件。
  • 弹珠 2 涂为蓝色,上面写着数字 1;弹珠 1 涂为绿色,因为蓝色和绿色不同,所以满足约束条件。
  • 弹珠 3 涂为蓝色,上面写着数字 5;弹珠 5 涂为红色,因为蓝色和红色不同,所以满足约束条件。
  • 弹珠 4 涂为绿色,上面写着数字 3;弹珠 3 涂为蓝色,因为绿色和蓝色不同,所以满足约束条件。
  • 弹珠 5 涂为红色,上面写着数字 4;弹珠 4 涂为绿色,因为红色和绿色不同,所以满足约束条件。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.