E. Lamps in a Line

Codeforces
IDCF100E
Time1000ms
Memory256MB
Difficulty
math
English · Original
Chinese · Translation
Formal · Original
There are _n_ lamps in a line. The lamps are numbered 1 to _n_ from left to right. There are also _n_ keys. When key number _i_ is pressed, all lamps number _x_ such that _i_|_x_ change their state. For two integer numbers _a_ and _b_, we say _a_|_b_ if and only if there exists an integer _c_ such that _a_ × _c_ = _b_. Amirali likes to play with the keys. He randomly pressed _k_ keys and wants to know the final state of the lamps. Help him by writing a Pike piece of code to solve this task. ## Input The first line of input contains a single integer _n_, the number of lamps (1 ≤ _n_ ≤ 105). The following line contains _n_ words. The _i_\-th word describes the initial state of lamp number _i_ (see samples for details). The following line contains a single integer _k_ (1 ≤ _k_ ≤ 104), the number of times a key is pressed. Then in the next line come _k_ integers in range \[1, _n_\] which are the numbers of the pressed keys. ## Output Write _n_ words to output. Describe the final state of the lamps. See samples for more details. [samples]
有一排 #cf_span[n] 盏灯,从左到右编号为 #cf_span[1] 到 #cf_span[n]。同时有 #cf_span[n] 个按键。当按下第 #cf_span[i] 个按键时,所有满足 #cf_span[i|x] 的灯 #cf_span[x] 都会改变状态。 对于两个整数 #cf_span[a] 和 #cf_span[b],我们说 #cf_span[a|b] 当且仅当存在整数 #cf_span[c] 使得 #cf_span[a × c = b]。 Amirali 喜欢玩这些按键。他随机按下了 #cf_span[k] 个按键,想知道灯的最终状态。请帮他写一段 #cf_span(class=[tex-font-style-underline], body=[Pike]) 代码来解决这个问题。 输入的第一行包含一个整数 #cf_span[n],表示灯的数量(#cf_span[1 ≤ n ≤ 105])。 第二行包含 #cf_span[n] 个单词,第 #cf_span[i] 个单词描述第 #cf_span[i] 盏灯的初始状态(详见样例)。 第三行包含一个整数 #cf_span[k](#cf_span[1 ≤ k ≤ 104]),表示按键被按下的次数。接下来一行包含 #cf_span[k] 个在范围 #cf_span[[1, n]] 内的整数,表示被按下的按键编号。 请输出 #cf_span[n] 个单词,描述灯的最终状态。详见样例。 ## Input 输入的第一行包含一个整数 #cf_span[n],表示灯的数量(#cf_span[1 ≤ n ≤ 105])。第二行包含 #cf_span[n] 个单词,第 #cf_span[i] 个单词描述第 #cf_span[i] 盏灯的初始状态(详见样例)。第三行包含一个整数 #cf_span[k](#cf_span[1 ≤ k ≤ 104]),表示按键被按下的次数。接下来一行包含 #cf_span[k] 个在范围 #cf_span[[1, n]] 内的整数,表示被按下的按键编号。 ## Output 请输出 #cf_span[n] 个单词,描述灯的最终状态。详见样例。 [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of lamps and keys. Let $ s = (s_1, s_2, \dots, s_n) \in \{0,1\}^n $ be the initial state of the lamps, where $ s_i \in \{0,1\} $ represents the initial state of lamp $ i $. Let $ K = (k_1, k_2, \dots, k_k) \in \{1, 2, \dots, n\}^k $ be the sequence of pressed keys, with $ k \in \mathbb{Z}^+ $ being the number of presses. **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 1 \leq k \leq 10^4 $ 3. For all $ i \in \{1, \dots, n\} $, $ s_i \in \{0,1\} $ 4. For all $ j \in \{1, \dots, k\} $, $ 1 \leq k_j \leq n $ **Objective** For each lamp $ i \in \{1, \dots, n\} $, let $ f(i) $ denote the number of keys $ k_j \in K $ such that $ k_j \mid i $. The final state of lamp $ i $ is: $$ s_i' = s_i \oplus (f(i) \bmod 2) $$ Output $ (s_1', s_2', \dots, s_n') $.
Samples
Input #1
2
off off
2
1 2
Output #1
on off
Input #2
3
off off on
6
1 1 1 1 2 2
Output #2
off off on
API Response (JSON)
{
  "problem": {
    "name": "E. Lamps in a Line",
    "description": {
      "content": "There are _n_ lamps in a line. The lamps are numbered 1 to _n_ from left to right. There are also _n_ keys. When key number _i_ is pressed, all lamps number _x_ such that _i_|_x_ change their state. ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF100E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are _n_ lamps in a line. The lamps are numbered 1 to _n_ from left to right. There are also _n_ keys. When key number _i_ is pressed, all lamps number _x_ such that _i_|_x_ change their state.\n\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "有一排 #cf_span[n] 盏灯,从左到右编号为 #cf_span[1] 到 #cf_span[n]。同时有 #cf_span[n] 个按键。当按下第 #cf_span[i] 个按键时,所有满足 #cf_span[i|x] 的灯 #cf_span[x] 都会改变状态。\n\n对于两个整数 #cf_span[a] 和 #cf_span[b],我们说 #cf_span[a|b] 当且仅当存在整数 #c...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of lamps and keys.  \nLet $ s = (s_1, s_2, \\dots, s_n) \\in \\{0,1\\}^n $ be the initial state of the lamps, where $ s_i \\in \\{0,1\\} $ represents...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments