A11939 | Adjacent Replacements
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occurrence of $1$ in the array $a$ with $2$ ;
- Replace each occurrence of $2$ in the array $a$ with $1$ ;
- Replace each occurrence of $3$ in the array $a$ with $4$ ;
- Replace each occurrence of $4$ in the array $a$ with $3$ ;
- Replace each occurrence of $5$ in the array $a$ with $6$ ;
- Replace each occurrence of $6$ in the array $a$ with $5$ ;
- $\dots$
- Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$ ;
- Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$ .
Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ( $2i - 1, 2i$ ) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above.
For example, for the array $a = [1, 2, 4, 5, 10]$ , the following sequence of arrays represents the algorithm:
$[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$ ) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$ ) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$ ) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$ ) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$ ) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$ ) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$ ) $\rightarrow$ $[1, 1, 3, 5, 9]$ . The later steps of the algorithm do not change the array.
Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occurrence of $1$ in the array $a$ with $2$ ;
- Replace each occurrence of $2$ in the array $a$ with $1$ ;
- Replace each occurrence of $3$ in the array $a$ with $4$ ;
- Replace each occurrence of $4$ in the array $a$ with $3$ ;
- Replace each occurrence of $5$ in the array $a$ with $6$ ;
- Replace each occurrence of $6$ in the array $a$ with $5$ ;
- $\dots$
- Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$ ;
- Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$ .
Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ( $2i - 1, 2i$ ) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above.
For example, for the array $a = [1, 2, 4, 5, 10]$ , the following sequence of arrays represents the algorithm:
$[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$ ) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$ ) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$ ) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$ ) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$ ) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$ ) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$ ) $\rightarrow$ $[1, 1, 3, 5, 9]$ . The later steps of the algorithm do not change the array.
Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.
输入格式
The first line of the input contains one integer number $n$ ( $1 \le n \le 1000$ ) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ) — the elements of the array.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ) — the elements of the array.
输出格式
Print $n$ integers — $b_1, b_2, \dots, b_n$ , where $b_i$ is the final value of the $i$ -th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$ . Note that you cannot change the order of elements in the array.
输入输出样例
输入 #1
5 1 2 4 5 10
输出 #1
1 1 3 5 9
输入 #2
10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
输出 #2
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
The first example is described in the problem statement.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted