#abc306c. C - Centers

C - Centers

Score : 250250 points

问题陈述

你给定一个长度为 3N3N 的序列 A=(A1,A2,,A3N)A=(A_1,A_2,\dots,A_{3N}),其中每个数字 1,2,,N1,2,\dots,N 恰好出现三次。

对于 i=1,2,,Ni=1,2,\dots,N,令 f(i)f(i) 表示 ii 在序列 AA 中的中间位置索引。按照 f(i)f(i) 的升序对 1,2,,N1,2,\dots,N 进行排序。

正式地,f(i)f(i) 定义如下:

  • 假设满足 Aj=iA_j = i 的所有 jj 分别为 α,β,γ (α<β<γ)\alpha,\beta,\gamma\ (\alpha < \beta < \gamma)。那么,f(i)=βf(i) = \beta

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A1,A2,,A3N)A=(A_1,A_2,\dots,A_{3N}) of length 3N3N where each of 1,2,1,2,\dots, and NN occurs exactly three times.

For i=1,2,,Ni=1,2,\dots,N, let f(i)f(i) be the index of the middle occurrence of ii in AA. Sort 1,2,,N1,2,\dots,N in ascending order of f(i)f(i).

Formally, f(i)f(i) is defined as follows.

  • Suppose that those jj such that Aj=iA_j = i are j=α,β,γ (α<β<γ)j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma). Then, f(i)=βf(i) = \beta.

Constraints

  • 1N1051\leq N \leq 10^5
  • 1AjN1 \leq A_j \leq N
  • ii occurs in AA exactly three times, for each i=1,2,,Ni=1,2,\dots,N.
  • All input values are integers.

Input

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

NN

A1A_1 A2A_2 \dots A3NA_{3N}

Output

Print the sequence of length NN obtained by sorting 1,2,,N1,2,\dots,N in ascending order of f(i)f(i), separated by spaces.

Sample Input 1

3
1 1 3 2 3 2 2 3 1

Sample Output 1

1 3 2
  • 11 occurs in AA at A1,A2,A9A_1,A_2,A_9, so f(1)=2f(1) = 2.
  • 22 occurs in AA at A4,A6,A7A_4,A_6,A_7, so f(2)=6f(2) = 6.
  • 33 occurs in AA at A3,A5,A8A_3,A_5,A_8, so f(3)=5f(3) = 5.

Thus, f(1)<f(3)<f(2)f(1) < f(3) < f(2), so 1,31,3, and 22 should be printed in this order.

Sample Input 2

1
1 1 1

Sample Output 2

1

Sample Input 3

4
2 3 4 3 4 1 3 1 1 4 2 2

Sample Output 3

3 4 1 2

update @ 2024/3/10 08:38:23