| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 64 | 19 | 16 | 36.364% |
You are given a sequence of length $N$: $A_0, A_1, \ldots, A_{N-1}$. It consists of only three kinds of integers: 1,ドル 2, 3$.
A tuple of indices $(i, j, k)$ is good if 0ドル \le i < j < k < N$ and it satisfies one of the two following conditions: either $A_i = 1, ,円 A_j = 2, ,円 A_k = 3$ or $A_i = 3, ,円 A_j = 2, ,円 A_k = 1$.
Your goal is find disjoint good tuples, as many of them as possible. A group of tuples is disjoint if no index is present in more than one tuple.
Find the maximum number of disjoint good tuples and print each tuple.
The first line contains an integer $N,ドル the length of the given sequence (1ドル \le N \le 600,000円$).
The next line contains $N$ integers: $A_0, A_1, \ldots, A_{N-1}$ (1ドル \le A_i \le 3$).
On the first line, print an integer $M,ドル the maximum number of disjoint good tuples.
On the next $M$ lines, print the tuples themselves. Each of these lines must contains three integers $i, j, k$ (0ドル \le i < j < k < N$) that describes a good tuple. All the printed tuples must be disjoint. If there are several solutions, print any one of them.
6 3 1 2 2 3 1
2 1 2 4 0 3 5
6 2 1 3 1 3 2
0