QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: jiangly

Posted at: 2025-12-13 00:16:57

Last updated: 2025-12-13 00:17:00

Back to Problem

题解

首先 $1$ 的左右 $c$ 个数(如果存在)分别可以任意交换。假设我们把左边的 $c$ 个数中的最小值(设为 $x$)到最左边,且这时它左边的 $c$ 个数(即 $1$ 左边的 $c+1$ 到 $2c$ 个数,如果左边的数不到 $2c$ 即为最左边的 $c$ 个数)都大于 $x$,则 $1$ 左边的 $2c-1$ 个数(不包括 $x$)都可以任意排列,但 $x$ 一定在 $1$ 左边的 $c$ 个数中。依此类推,会有一个数一定在 $1$ 的左边 $2c$ 个数中,$3c$ 个数中……实现时,把所有数从小到大加入即可。时间复杂度 $O(n)$。

Comments

No comments yet.