問題一覧 > 通常問題

No.2879 Range Flip Queries

レベル : / AI推定難易度 : 275 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 110
作問者 : Iroha_3856 / テスター : hiro1729 Rac tikuwa_
お気に入りにしたユーザー ProblemId : 11009 / 自分の提出
問題文最終更新日: 2024-09-08 08:23:38
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 445 (菁々祭プログラミングコンテスト2024) (順位表) の他の問題:

Problem Statement

You are given positive integers $N, Q$ and a sequence $A = (A_1, A_2, \ldots, A_N)$ of length $N$ whose elements are all $0$ or $1$.

For $i = 1, 2, \ldots, Q$, perform the following operation on $A$.

  • You are given $L_i, R_i$. Flip $A_{L_i}, A_{L_i+1}, \ldots, A_{R_i}$.

Output $A$ after all the operations are finished.

Here, to flip $x$ means to make it $x = 1$ if $x = 0$, and to make it $x = 0$ if $x = 1$.

Under these constraints, no $x$ with $x \neq 0$ and $x \neq 1$ is ever flipped.

Input

$N\ Q$
$A_1\ A_2\ \ldots\ A_N$
$L_1\ R_1$
$L_2\ R_2$
$\vdots$
$L_Q\ R_Q$

All input satisfies the following constraints.

  • $1 \leq N, Q \leq 5 \times 10^{5}$
  • $A_i = 0$ or $A_i = 1$
  • $1 \leq L_i \leq R_i \leq N$
  • All input values are integers.

Output

Output $A$ after performing all the operations in the following format, followed by a newline at the end.

$A_1\ A_2\ \ldots\ A_N$

Sample

Sample 1
Input
5 3
0 0 0 0 0
1 5
2 4
3 3
Output
1 0 1 0 1

Initially, $A = (0, 0, 0, 0, 0)$.

In query number $1$, $A_1, A_2, A_3, A_4, A_5$ are flipped, and $A = (1, 1, 1, 1, 1)$ results.

In query number $2$, $A_2, A_3, A_4$ are flipped, and $A = (1, 0, 0, 0, 1)$ results.

In query number $3$, $A_3$ is flipped, and $A = (1, 0, 1, 0, 1)$ results.

Therefore, after all the operations, $A = (1, 0, 1, 0, 1)$, so output this.

Sample 2
Input
10 7
1 0 1 1 1 1 0 0 1 1
3 6
1 10
4 4
1 7
3 3
2 10
8 8
Output
1 1 0 0 1 1 1 1 1 1

Sample 3
Input
30 24
1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1
30 30
13 25
30 30
14 24
2 16
10 28
22 24
15 24
9 29
6 26
24 29
2 15
27 28
3 21
17 20
16 16
15 22
27 28
17 28
14 28
25 28
13 22
15 22
15 27
Output
1 0 0 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 1 0 1 0 1 1 1 1

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。