103062: [Atcoder]ABC306 C - Centers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:6 Solved:0

Description

Score : $250$ points

Problem Statement

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

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

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

  • Suppose that those $j$ such that $A_j = i$ are $j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma)$. Then, $f(i) = \beta$.

Constraints

  • $1\leq N \leq 10^5$
  • $1 \leq A_j \leq N$
  • $i$ occurs in $A$ exactly three times, for each $i=1,2,\dots,N$.
  • All input values are integers.

Input

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

$N$
$A_1$ $A_2$ $\dots$ $A_{3N}$

Output

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


Sample Input 1

3
1 1 3 2 3 2 2 3 1

Sample Output 1

1 3 2
  • $1$ occurs in $A$ at $A_1,A_2,A_9$, so $f(1) = 2$.
  • $2$ occurs in $A$ at $A_4,A_6,A_7$, so $f(2) = 6$.
  • $3$ occurs in $A$ at $A_3,A_5,A_8$, so $f(3) = 5$.

Thus, $f(1) < f(3) < f(2)$, so $1,3$, and $2$ 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

Input

题意翻译

Syx 给你 $3 \times N$ 个数,其中 Syx 可以保证:$1 \sim N$ 之间的所有数都出现了 $3$ 次,请你将 $1 \sim N$ 之间的数每个出现在**第 $2$ 个位置的下标**进行排序,并从小到大输出**原数**。 [By Saint_ying_xtf](https://www.luogu.com.cn/user/852144)

Output

得分:250分

问题描述

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

对于$i=1,2,\dots,N$,令$f(i)$表示$A$中数字$i$的中间出现的下标。 将$1,2,\dots,N$按照$f(i)$的升序排序。

形式化地,$f(i)$定义如下。

  • 假设使得$A_j = i$的$j$的值为$j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma)$。 那么,$f(i) = \beta$。

约束

  • $1\leq N \leq 10^5$
  • $1 \leq A_j \leq N$
  • $i$在$A$中恰好出现三次,对于每个$i=1,2,\dots,N$。
  • 所有的输入值都是整数。

输入

输入数据通过标准输入给出,如下所示:

$N$
$A_1$ $A_2$ $\dots$ $A_{3N}$

输出

按照$f(i)$的升序排序,将$1,2,\dots,N$打印成长度为$N$的序列,数字之间用空格分隔。


样例输入1

3
1 1 3 2 3 2 2 3 1

样例输出1

1 3 2
  • $1$在$A$中出现在$A_1,A_2,A_9$,所以$f(1) = 2$。
  • $2$在$A$中出现在$A_4,A_6,A_7$,所以$f(2) = 6$。
  • $3$在$A$中出现在$A_3,A_5,A_8$,所以$f(3) = 5$。

因此,$f(1) < f(3) < f(2)$,所以应该按这个顺序打印出$1,3$和$2$。


样例输入2

1
1 1 1

样例输出2

1

样例输入3

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

样例输出3

3 4 1 2

HINT

3n个数,1~n每个数字都出现3次,他们的排名为每个数字第二次出现的位置,按照排名从小到大输出?

加入题单

算法标签: