Logo
(追記) (追記ここまで)

31114번 - Game Theory 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB275519.231%

문제

For a string $s_1\dots s_n$ of $n$ bits (i.e., zeros and ones), Bobo computes the $f$-value of $s_1\dots s_n$ by playing the following game.

  • If all the bits are zero, the game ends.
  • If there are $k$ ones in the bit string, Bobo flips the $k$-th bit, i.e., $s_k$.
  • The $f$-value of the bit string is the number of flips Bobo has performed before the game ends.

Formally,

  • If $s_1 = \dots = s_n = 0,ドル $f(s_1 \dots s_n) = 0$.
  • Otherwise, assuming that $k = s_1 + \dots + s_n,ドル $f(s_1 \dots s_n) = f(s_1 \dots s_{k - 1} \overline{s_k} s_{k + 1} \dots s_n) + 1$ where $\overline{c}$ denotes the flip of the bit $c$ such as $\overline{0} = 1$ and $\overline{1} = 0$.

Now, Bobo has a bit string $s_1 \dots s_n$ subjecting to $q$ changes, where the $i$-th change is to flip all the bits among $s_{l_i} \dots s_{r_i}$ for given $l_i,ドル $r_i$. Find the $f$-value modulo 998244353ドル$ of the bit string after each change.

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains two integers $n$ and $q$.

The second line contains $n$ bits $s_1 \dots s_n$.

For the following $q$ lines, the $i$-th line contains two integers $l_i$ and $r_i$.

출력

For each change, output an integer which denotes the $f$-value modulo 998244353ドル$.

제한

  • 1ドル \le n \le 2 \times 10^5$
  • 1ドル \le q \le 2 \times 10^5$
  • $s_i \in \{0, 1\}$ for each 1ドル \leq i \leq n$
  • 1ドル \leq l_i \leq r_i \leq n$ for each 1ドル \leq i \leq q$
  • In each input, the sum of $n$ does not exceed 2ドル \times 10^5$. The sum of $q$ does not exceed 2ドル \times 10^5$.

예제 입력 1

3 2
010
1 2
2 3
5 1
00000
1 5

예제 출력 1

1
3
5

노트

For the first test case, the string becomes "100" after the first change. $f($100$) = f($000$) + 1 = 1$. And it becomes "111" after the second change. $f($111$) = f($110$) + 1 = f($100$) + 2 = f($000$) + 3 = 3$.

출처

Contest > Open Cup > 2020/2021 Season > Stage 18: Grand Prix of Beijing E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /