A16210 | Autosynthesis
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Chaneka writes down an array $a$ of $n$ positive integer elements. Initially, all elements are not circled. In one operation, Chaneka can circle an element. It is possible to circle the same element more than once.
After doing all operations, Chaneka makes a sequence $r$ consisting of all uncircled elements of $a$ following the order of their indices.
Chaneka also makes another sequence $p$ such that its length is equal to the number of operations performed and $p_i$ is the index of the element that is circled in the $i$ -th operation.
Chaneka wants to do several operations such that sequence $r$ is equal to sequence $p$ . Help her achieve this, or report if it is impossible! Note that if there are multiple solutions, you can print any of them.
After doing all operations, Chaneka makes a sequence $r$ consisting of all uncircled elements of $a$ following the order of their indices.
Chaneka also makes another sequence $p$ such that its length is equal to the number of operations performed and $p_i$ is the index of the element that is circled in the $i$ -th operation.
Chaneka wants to do several operations such that sequence $r$ is equal to sequence $p$ . Help her achieve this, or report if it is impossible! Note that if there are multiple solutions, you can print any of them.
输入格式
The first line contains a single integer $n$ ( $1 \leq n \leq 2\cdot10^5$ ) — the size of array $a$ .
The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ( $1\leq a_i\leq n$ ).
The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ( $1\leq a_i\leq n$ ).
输出格式
A single line containing $-1$ if it is impossible.
Otherwise, the output consists of two lines. The first line contains an integer $z$ representing the number of operations performed. The second line contains $z$ integers, the $i$ -th integer represents the index of the element circled in the $i$ -th operation. If there are multiple solutions, you can print any of them.
Otherwise, the output consists of two lines. The first line contains an integer $z$ representing the number of operations performed. The second line contains $z$ integers, the $i$ -th integer represents the index of the element circled in the $i$ -th operation. If there are multiple solutions, you can print any of them.
输入输出样例
输入 #1
5 3 4 2 2 3
输出 #1
3 3 2 3
输入 #2
3 1 2 3
输出 #2
-1
In the first example, doing the operations like the example output gives the following results:
- Element $a_2$ gets circled $1$ time.
- Element $a_3$ gets circled $2$ times.
- The uncircled elements (ordered by their indices) are $a_1$ , $a_4$ , and $a_5$ . So $r=[3,2,3]$ .
- $p=[3,2,3]$
Therefore, $r=p$ .
In the second example, it is impossible.
- Element $a_2$ gets circled $1$ time.
- Element $a_3$ gets circled $2$ times.
- The uncircled elements (ordered by their indices) are $a_1$ , $a_4$ , and $a_5$ . So $r=[3,2,3]$ .
- $p=[3,2,3]$
Therefore, $r=p$ .
In the second example, it is impossible.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted