問題一覧 > 通常問題

No.3238 Shadow

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 57
作問者 : 👑 箱星 / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 9922 / 自分の提出
問題文最終更新日: 2025-08-12 18:32:37
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 478 オムニバス (順位表) の他の問題:

Problem Statement

You are given a permutation $(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$. Place $N$ points $(i,P_i)$ on the coordinate plane.

When $2$ points $A=(a_1,a_2),B=(b_1,b_2)$ satisfy $a_1\lt b_1$ and $a_2\lt b_2$, we say that $B$ is in the shadow of $A$.

Perform the following operation.

  1. Among the points currently on the plane, let $S$ be the set of points that are not in the shadow of any point.
  2. Output the minimum $x$-coordinate and the minimum $y$-coordinate of the points in $S$.
  3. Remove the points in $S$ from the plane.
  4. If there are no points on the plane, terminate; otherwise, return to 1.

Constraints

  • $1\le N\le 2\times 10^5$
  • $(P_1,P_2,\ldots,P_N)$ is a permutation of $(1,2,\ldots,N)$
  • All inputs are integers

Input

$N$
$P_1$ $P_2$ $\cdots$ $P_N$

Output

Let $M$ be the number of outputs, and let $x_i, y_i$ be the minimum $x$-coordinate and the minimum $y$-coordinate, respectively, in the $i$-th output. Print in the following format.

$x_1$ $y_1$
$x_2$ $y_2$
$\vdots$
$x_M$ $y_M$

Sample

Sample 1
Input
5
2 4 3 1 5
Output
1 1
2 3
5 5

Place the $5$ points $(1,2), (2,4), (3,3), (4,1), (5,5)$. The set of points that are not in the shadow of any point is $S=\{(1,2),(4,1)\}$. Output 1 1.

After removing the points in $S$, the remaining points are $(2,4), (3,3), (5,5)$. At this point, $S=\{(2,4),(3,3)\}$. Output 2 3.

After removing the points in $S$ again, the remaining point is $(5,5)$. Output 5 5.

After that, there are no points left, so the process terminates.

Sample 2
Input
4
4 3 2 1
Output
1 1

Sample 3
Input
9
9 6 4 2 8 5 3 1 7
Output
1 1
5 3
9 7

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。