A9612 | Alex and Complicated Task
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task.
Given a sequence of integer numbers $a_{1},a_{2},...,a_{n}$ . You are to find a longest sequence $b_{1},b_{2},...,b_{4m}$ , that satisfies the following conditions:
- $b_{4k+1}=b_{4k+3}$ for all valid integer $k$ ;
- $b_{4k+2}=b_{4k+4}$ for all valid integer $k$ ;
- sequence $b$ is subsequence of $a$ (not necessarily contiguous subsequence).
And finally... Alex had given this complicated task to George, and George gave it to you. Help George to cope with the task.
Given a sequence of integer numbers $a_{1},a_{2},...,a_{n}$ . You are to find a longest sequence $b_{1},b_{2},...,b_{4m}$ , that satisfies the following conditions:
- $b_{4k+1}=b_{4k+3}$ for all valid integer $k$ ;
- $b_{4k+2}=b_{4k+4}$ for all valid integer $k$ ;
- sequence $b$ is subsequence of $a$ (not necessarily contiguous subsequence).
And finally... Alex had given this complicated task to George, and George gave it to you. Help George to cope with the task.
输入格式
The first line contains a single integer $n$ $(1<=n<=5·10^{5})$ . The next line contains $n$ integers $a_{1},a_{2},...,a_{n}$ $(1<=a_{i}<=10^{9})$ .
输出格式
In the first line print a single integer $4m$ — the maximal possible length of required sequence $b$ . In the second line print $4m$ integers $b_{1},b_{2},...,b_{4m}$ , that is required sequence.
If there are multiple optimal answers you may print any of them.
If there are multiple optimal answers you may print any of them.
输入输出样例
输入 #1
4 3 5 3 5
输出 #1
4 3 5 3 5
输入 #2
10 35 1 2 1 2 35 100 200 100 200
输出 #2
8 1 2 1 2 100 200 100 200
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted