QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#6537. 一、二、三

Statistics

给定一个长度为 $N$ 的序列:$A_0, A_1, \dots, A_{N-1}$。它仅由三种整数组成:1, 2, 3。

如果下标元组 $(i, j, k)$ 满足 $0 \le i < j < k < N$ 且满足以下两个条件之一,则称其为“好”元组: $A_i = 1, A_j = 2, A_k = 3$ 或者 $A_i = 3, A_j = 2, A_k = 1$。

你的目标是找到尽可能多的不相交的好元组。如果一组元组中没有任何下标在多于一个元组中出现,则称这组元组是不相交的。

请找出不相交的好元组的最大数量,并输出每个元组。

输入格式

第一行包含一个整数 $N$,表示给定序列的长度 ($1 \le N \le 600\,000$)。 第二行包含 $N$ 个整数:$A_0, A_1, \dots, A_{N-1}$ ($1 \le A_i \le 3$)。

输出格式

第一行输出一个整数 $M$,表示不相交的好元组的最大数量。 接下来的 $M$ 行,每行输出一个元组。每行包含三个整数 $i, j, k$ ($0 \le i < j < k < N$),描述一个好元组。所有输出的元组必须是不相交的。如果存在多种方案,输出其中任意一种即可。

样例

样例输入 1

6
3 1 2 2 3 1

样例输出 1

2
1 2 4
0 3 5

样例输入 2

6
2 1 3 1 3 2

样例输出 2

0

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1567Editorial Open集训队作业 解题报告 by 周裕杭Anonymous2026-04-17 20:13:51 Download
#539Editorial Open集训队作业 解题报告 by 林祺昊Qingyu2026-01-02 22:00:56 Download
#468EditorialOpen题解KiharaTouma2026-01-02 22:00:33View

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 1
IDTypeStatusTitlePosted ByLast UpdatedActions
#276General DiscussionOpenChecker UpdateQingyu2025-12-26 14:09:16View

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.