A. Adjacent Replacements

Codeforces
IDCF1006A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
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. ## Input 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. ## Output 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. [samples] ## Note The first example is described in the problem statement.
Mishka 得到了一个长度为 $n$ 的整数数组 $a$ 作为生日礼物(真是惊喜!)。 Mishka 不喜欢这份礼物,想要以某种方式改变它。他发明了一个算法,并称之为 "Mishka 的相邻替换算法"。该算法可以表示为一系列步骤: 注意,该算法中间的省略号表示 Mishka 对每一对相邻整数 $(2i - 1, 2i)$,对每个 $i \in \{1, 2, dots.h, 5 \dot.op 10^8\}$ 均按上述方式应用替换。 例如,对于数组 $a = [ 1, 2, 4, 5, 10 ]$,以下数组序列表示该算法: $[ 1, 2, 4, 5, 10 ]$ $arrow.r$(将所有 $1$ 替换为 $2$)$arrow.r$ $[ 2, 2, 4, 5, 10 ]$ $arrow.r$(将所有 $2$ 替换为 $1$)$arrow.r$ $[ 1, 1, 4, 5, 10 ]$ $arrow.r$(将所有 $3$ 替换为 $4$)$arrow.r$ $[ 1, 1, 4, 5, 10 ]$ $arrow.r$(将所有 $4$ 替换为 $3$)$arrow.r$ $[ 1, 1, 3, 5, 10 ]$ $arrow.r$(将所有 $5$ 替换为 $6$)$arrow.r$ $[ 1, 1, 3, 6, 10 ]$ $arrow.r$(将所有 $6$ 替换为 $5$)$arrow.r$ $[ 1, 1, 3, 5, 10 ]$ $arrow.r$ $dots.h$ $arrow.r$ $[ 1, 1, 3, 5, 10 ]$ $arrow.r$(将所有 $10$ 替换为 $9$)$arrow.r$ $[ 1, 1, 3, 5, 9 ]$。算法的后续步骤不再改变数组。 Mishka 非常懒,不想自己手动应用这些更改。但他非常关心它们的结果。请帮助他找出结果。 输入的第一行包含一个整数 $n$($1 lt.eq n lt.eq 1000$)——Mishka 生日礼物中元素的个数(令人惊讶的是,这是一个数组)。 输入的第二行包含 $n$ 个整数 $a_1, a_2, dots.h, a_n$($1 lt.eq a_i lt.eq 10^9$)——数组的元素。 请输出 $n$ 个整数——$b_1, b_2, dots.h, b_n$,其中 $b_i$ 是将 "Mishka 的相邻替换算法" 应用于数组 $a$ 后第 $i$ 个元素的最终值。注意,你不能改变数组中元素的顺序。 第一个例子已在问题描述中给出。 ## Input 输入的第一行包含一个整数 $n$($1 lt.eq n lt.eq 1000$)——Mishka 生日礼物中元素的个数(令人惊讶的是,这是一个数组)。输入的第二行包含 $n$ 个整数 $a_1, a_2, dots.h, a_n$($1 lt.eq a_i lt.eq 10^9$)——数组的元素。 ## Output 请输出 $n$ 个整数——$b_1, b_2, dots.h, b_n$,其中 $b_i$ 是将 "Mishka 的相邻替换算法" 应用于数组 $a$ 后第 $i$ 个元素的最终值。注意,你不能改变数组中元素的顺序。 [samples] ## Note 第一个例子已在问题描述中给出。
**Definitions** Let $ n \in \mathbb{Z} $ be the length of the array. Let $ A = (a_1, a_2, \dots, a_n) $ be the input array, where $ a_i \in \mathbb{Z} $ for all $ i \in \{1, \dots, n\} $. Let $ R: \mathbb{Z} \to \mathbb{Z} $ be the transformation function induced by Mishka’s Adjacent Replacements Algorithm, defined as: For each $ k \in \mathbb{Z}^+ $, - If $ k $ is odd, then $ R(k) = k + 1 $, - If $ k $ is even, then $ R(k) = k - 1 $. The algorithm applies $ R $ iteratively to all elements of the array in sequence for all adjacent pairs $ (2i-1, 2i) $, $ i = 1, 2, \dots, 5 \times 10^8 $. **Constraints** 1. $ 1 \le n \le 1000 $ 2. $ 1 \le a_i \le 10^9 $ for all $ i \in \{1, \dots, n\} $ **Objective** Compute the final array $ B = (b_1, b_2, \dots, b_n) $, where for each $ i \in \{1, \dots, n\} $: $$ b_i = \begin{cases} a_i - 1 & \text{if } a_i \text{ is even} \\ a_i & \text{if } a_i \text{ is odd} \end{cases} $$
Samples
Input #1
5
1 2 4 5 10
Output #1
1 1 3 5 9
Input #2
10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
Output #2
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
API Response (JSON)
{
  "problem": {
    "name": "A. Adjacent Replacements",
    "description": {
      "content": "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 \"Mi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1006A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).\n\nMishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it \"Mi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Mishka 得到了一个长度为 $n$ 的整数数组 $a$ 作为生日礼物(真是惊喜!)。\n\nMishka 不喜欢这份礼物,想要以某种方式改变它。他发明了一个算法,并称之为 \"Mishka 的相邻替换算法\"。该算法可以表示为一系列步骤:\n\n注意,该算法中间的省略号表示 Mishka 对每一对相邻整数 $(2i - 1, 2i)$,对每个 $i \\in \\{1, 2, dots.h, 5 \\dot.o...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the array.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be the input array, where $ a_i \\in \\mathbb{Z} $ for all $ i \\in \\{1, \\dots, n\\} $.  \n\nLet $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments