7039.Bit Inversions

Time Limit: 1s Memory Limit: 512MB

There is a bit string consisting of $n$ bits. Then, there are some changes that invert one given bit. Your task is to report, after each change, the length of the longest substring whose each bit is the same.

Input Format(From the terminal/stdin)

The first input line has a bit string consisting of $n$ bits. The bits are numbered $1,2,\ldots,n$ .

The next line contains an integer $m$ : the number of changes.

The last line contains $m$ integers $x_1,x_2,\ldots,x_m$ describing the changes.

  • $1 \le n \le 2 \cdot 10^5$
  • $1 \le m \le 2 \cdot 10^5$
  • $1 \le x_i \le n$

Output Format(To the terminal/stdout)

After each change, print the length of the longest substring whose each bit is the same.

Sample Input

Copy
001011
3
3 2 5
      \n
 \n
 · · \n

Sample Output

Copy
4 2 3
 · · \n

The bit string first becomes 000011 , then 010011 , and finally 010001 .

Source: CSES, Additional Problems I, 1188

Submit

请先 登录

© 2025 FAQs