CF1847D.Professor Higashikata

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss be a binary string of length nn. An operation on ss is defined as choosing two distinct integers ii and jj (1≤i<j≤n1 \leq i \lt j \leq n), and swapping the characters si,sjs_i, s_j.

Consider the mm strings t1,t2,…,tmt_1, t_2, \ldots, t_m, where tit_i is the substring †^\dagger of ss from lil_i to rir_i. Define t(s)=t1+t2+…+tmt(s) = t_1+t_2+\ldots+t_m as the concatenation of the strings tit_i in that order.

There are qq updates to the string. In the ii-th update sxis_{x_i} gets flipped. That is if sxi=1s_{x_i}=1, then sxis_{x_i} becomes 00 and vice versa. After each update, find the minimum number of operations one must perform on ss to make t(s)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 aa is a substring of a string bb if aa can be obtained from bb 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 aa is lexicographically larger than a string bb of the same length if and only if the following holds:

  • in the first position where aa and bb differ, the string aa has a 11, and the string bb has a 00.

乔鲁克厌倦了在杜王町的平静生活。他追随侄子东方仗助的脚步,决定努力学习,成为一名计算机科学教授。在上网查阅竞赛编程题目时,他遇到了下面这道题:

设 ss 是一个长度为 nn 的二进制字符串。对 ss 执行一次操作定义为:选择两个不同的整数 ii 和 jj(满足 1≤i<j≤n1 \leq i < j \leq n),并交换字符 sis_i 与 sjs_j。

考虑 mm 个字符串 t1,t2,…,tmt_1, t_2, \ldots, t_m,其中 tit_i 是 ss 在区间 [li,ri][l_i, r_i] 上的子串†^\dagger。定义 t(s)=t1+t2+…+tmt(s) = t_1 + t_2 + \ldots + t_m 为这些字符串 tit_i 按此顺序拼接而成的字符串。

共有 qq 次对字符串 ss 的更新操作。在第 ii 次更新中,sxis_{x_i} 被翻转(即若 sxi=1s_{x_i}=1,则变为 00;若为 00,则变为 11)。每次更新后,请计算:为使 t(s)t(s) 的字典序‡^\ddagger尽可能大,需对 ss 执行的最少操作次数。

注意:实际上并不真正执行任何操作,我们只关心所需操作的最少次数。

请帮助乔鲁克实现他的梦想,解决该问题。

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

†\dagger 若字符串 aa 可通过从字符串 bb 的开头删除若干(可能为零或全部)字符、并从结尾删除若干(可能为零或全部)字符而得到,则称 aa 是 bb 的子串。

‡\ddagger 对于两个等长字符串 aa 和 bb,当且仅当满足以下条件时,称 aa 的字典序大于 bb:

  • 在 aa 与 bb 首次出现差异的位置上,aa 对应字符为 11,而 bb 对应字符为 00。

输入格式

The first line contains three integers nn, mm, qq (1≤n,m,q≤2⋅1051 \leq n,m,q \leq 2 \cdot 10^5).

The next line contains a binary string ss of length nn, consisting only of digits 00 and 11.

The ii-th line of the next mm lines contains two integers lil_i and rir_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n).

The ii-th line of the next qq lines contains a single integer xix_i (1≤xi≤n1 \leq x_i \leq n).

第一行包含三个整数 nn、mm、qq(1≤n,m,q≤2⋅1051 \leq n,m,q \leq 2 \cdot 10^5)。

第二行包含一个长度为 nn 的二进制字符串 ss,仅由数字 00 和 11 组成。

接下来 mm 行中的第 ii 行包含两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n)。

接下来 qq 行中的第 ii 行包含一个整数 xix_i(1≤xi≤n1 \leq x_i \leq n)。

输出格式

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

输出 qq 个整数。其中第 ii 个整数表示:在第 ii 轮中,为使字符串 ss 变为字典序最大的可能字符串 t(s)t(s) 所需执行的最少操作次数。

输入输出样例

  • 输入#1

    2 2 4
    01
    1 2
    1 2
    1
    1
    2
    2

    输出#1

    0
    1
    0
    1
  • 输入#2

    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

    输出#2

    2
    3
    2
    2
    1
    2
    2
    2
    2
    2

说明/提示

In the first test case,

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

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

After the 22-nd query, ss becomes 0101 and consequently tt becomes 01010101. You need to perform 11 operation by swapping s1s_1 and s2s_2. Consequently, t(s)t(s) becomes 10101010 which is the lexicographically largest string you can achieve.

在第一个测试用例中,

最初,t(s)=s(1,2)+s(1,2)=0101t(s) = s(1,2) + s(1,2) = 0101。

执行第 11 个查询后,ss 变为 1111,因此 tt 变为 11111111。此时无需执行任何操作,因为 t(s)t(s) 已经是字典序最大的字符串。

执行第 22 个查询后,ss 变为 0101,因此 tt 变为 01010101。你需要执行 11 次操作:交换 s1s_1 和 s2s_2。于是,t(s)t(s) 变为 10101010,这是你能得到的字典序最大的字符串。

输入解题思路,AI测评打分。不知道怎么写?

首页