310532: CF1847D. Professor Higashikata

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Professor Higashikatatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Josuke is tired of his peaceful life in Morioh. Following in his nephew Jotaro's footsteps, he decides to study hard and become a professor of computer science. While looking up competitive programming problems online, he comes across the following one:

Let $s$ be a binary string of length $n$. An operation on $s$ is defined as choosing two distinct integers $i$ and $j$ ($1 \leq i < j \leq n$), and swapping the characters $s_i, s_j$.

Consider the $m$ strings $t_1, t_2, \ldots, t_m$, where $t_i$ is the substring $^\dagger$ of $s$ from $l_i$ to $r_i$. Define $t(s) = t_1+t_2+\ldots+t_m$ as the concatenation of the strings $t_i$ in that order.

There are $q$ updates to the string. In the $i$-th update $s_{x_i}$ gets flipped. That is if $s_{x_i}=1$, then $s_{x_i}$ becomes $0$ and vice versa. After each update, find the minimum number of operations one must perform on $s$ to make $t(s)$ lexicographically as large$^\ddagger$ as possible.

Note that no operation is actually performed. We are only interested in the number of operations.

Help Josuke in his dream by solving the problem for him.

——————————————————————

$\dagger$ A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

$\ddagger$ A string $a$ is lexicographically larger than a string $b$ of the same length if and only if the following holds:

  • in the first position where $a$ and $b$ differ, the string $a$ has a $1$, and the string $b$ has a $0$.
Input

The first line contains three integers $n$, $m$, $q$ ($1 \leq n,m,q \leq 2 \cdot 10^5$).

The next line contains a binary string $s$ of length $n$, consisting only of digits $0$ and $1$.

The $i$-th line of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1 \leq l_i \leq r_i \leq n$).

The $i$-th line of the next $q$ lines contains a single integer $x_i$ ($1 \leq x_i \leq n$).

Output

Print $q$ integers. The $i$-th integer is the minimum number of operations that need to be performed on $s$ to get the lexicographically largest possible string $t(s)$ in the $i$-th round.

ExamplesInput
2 2 4
01
1 2
1 2
1
1
2
2
Output
0
1
0
1
Input
8 6 10
10011010
5 6
2 3
6 8
5 7
5 8
6 8
3
5
6
2
5
2
5
8
4
1
Output
2
3
2
2
1
2
2
2
2
2
Note

In the first test case,

Originally, $t(s) = s(1,2) + s(1,2) = 0101$.

After the $1$-st query, $s$ becomes $11$ and consequently $t$ becomes $1111$. You don't need to perform any operation as $t(s)$ is already the lexicographically largest string possible.

After the $2$-nd query, $s$ becomes $01$ and consequently $t$ becomes $0101$. You need to perform $1$ operation by swapping $s_1$ and $s_2$. Consequently, $t(s)$ becomes $1010$ which is the lexicographically largest string you can achieve.

Input

题意翻译

给出一个长度为 $n$ 的字符串 $s$,字符串仅由 `0` 或 `1` 构成。 给出 $m$ 个区间 $[l_i,r_i]$ ($1\le i\le m$,$1\le l_i\le r_i\le n$),你需要将字符串 $s$ 的子段 $[l_i,r_i]$ 依次拼接,得到新的字符串 $t$。 你可以对字符串 $s$ 进行操作,每次操作可以交换任意两个字符的位置,注意操作不是实际改变,不会影响后续的询问。定义对于字符串 $s$,$f(s)$ 表示最小的操作次数,使得拼接得到的新字符串 $t$ 的字典序最大。 然后有 $q$ 次询问,每次询问给出一个位置 $x_i$,表示将原字符串 $s$ 的 $x_i$ 位置取反,注意是实际改变,会影响后续的询问。相应的,$t$ 字符串也会发生改变。你需要求出每次询问后,$f(s)$ 的值。 By [Binary_1110011_](https://www.luogu.com.cn/user/241485)

Output

题目大意:
给定一个长度为n的01字符串s。定义一种操作为在s中选择两个不同的位置i和j(1≤i
考虑m个子串t_1, t_2, ..., t_m,其中t_i是s从l_i到r_i的子串。定义t(s) = t_1 + t_2 + ... + t_m为按顺序连接的字符串t_i。

有q个更新操作,在第i次更新中,s_{x_i}会被翻转。即如果s_{x_i}=1,那么s_{x_i}变为0,反之亦然。在每次更新后,找到使t(s)字典序尽可能大的最小操作次数。

注意,实际上并不执行任何操作。我们只关心操作次数。

输入输出数据格式:
输入:
第一行包含三个整数n, m, q(1≤n, m, q≤2×10^5)。
下一行包含一个长度为n的01字符串s。
接下来m行,每行包含两个整数l_i和r_i(1≤l_i≤r_i≤n)。
再接下来q行,每行包含一个整数x_i(1≤x_i≤n)。

输出:
输出q个整数,第i个整数表示在第i轮中需要执行的最小操作次数,以使t(s)字典序尽可能大。题目大意: 给定一个长度为n的01字符串s。定义一种操作为在s中选择两个不同的位置i和j(1≤i

加入题单

上一题 下一题 算法标签: