Game Theory

시간 제한1초메모리 제한1024 MB

요약
구간 뒤집기가 일어날 때마다 모든 비트가 0이 될 때까지 이 뒤집기 게임이 몇 번 움직이는지 구한다.
난이도

어려움10점 중 8점

유형
수학, 조합론, 세그먼트 트리, 게임 이론
정답자
아직 제출이 없습니다

문제

For a string s_1…s_ns\_1\dots s\_n of nn bits (i.e., zeros and ones), Bobo computes the ff-value of s_1…s_ns\_1\dots s\_n by playing the following game.

  • If all the bits are zero, the game ends.
  • If there are kk ones in the bit string, Bobo flips the kk-th bit, i.e., s_ks\_k.
  • The ff-value of the bit string is the number of flips Bobo has performed before the game ends.

Formally,

  • If s_1=⋯=s_n=0s\_1 = \dots = s\_n = 0, f(s_1…s_n)=0f(s\_1 \dots s\_n) = 0.
  • Otherwise, assuming that k=s_1+⋯+s_nk = s\_1 + \dots + s\_n, f(s_1…s_n)=f(s_1…s_k−1s_k‾s_k+1…s_n)+1f(s\_1 \dots s\_n) = f(s\_1 \dots s\_{k - 1} \overline{s\_k} s\_{k + 1} \dots s\_n) + 1 where c‾\overline{c} denotes the flip of the bit cc such as 0‾=1\overline{0} = 1 and 1‾=0\overline{1} = 0.

Now, Bobo has a bit string s_1…s_ns\_1 \dots s\_n subjecting to qq changes, where the ii-th change is to flip all the bits among s_l_i…s_r_is\_{l\_i} \dots s\_{r\_i} for given l_il\_i, r_ir\_i. Find the ff-value modulo 998244353998244353 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 nn and qq.

The second line contains nn bits s_1…s_ns\_1 \dots s\_n.

For the following qq lines, the ii-th line contains two integers l_il\_i and r_ir\_i.

출력

For each change, output an integer which denotes the ff-value modulo 998244353998244353.

제한

  • 1≤n≤2×1051 \le n \le 2 \times 10^5
  • 1≤q≤2×1051 \le q \le 2 \times 10^5
  • s_i∈0,1s\_i \in \\{0, 1\\} for each 1≤i≤n1 \leq i \leq n
  • 1≤l_i≤r_i≤n1 \leq l\_i \leq r\_i \leq n for each 1≤i≤q1 \leq i \leq q
  • In each input, the sum of nn does not exceed 2×1052 \times 10^5. The sum of qq does not exceed 2×1052 \times 10^5.

힌트

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

예제1

  1. 예제 1

    입력
    3 2
    010
    1 2
    2 3
    5 1
    00000
    1 5
    
    예상 출력
    1
    3
    5