CF145E.Lucky Queries

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya brought home string s with the length of n. The string only consists of lucky digits. The digits are numbered from the left to the right starting with 1. Now Petya should execute m queries of the following form:

  • switch l r — "switch" digits (i.e. replace them with their opposites) at all positions with indexes from l to r, inclusive: each digit 4 is replaced with 7 and each digit 7 is replaced with 4 (1 ≤ l ≤ r ≤ n);
  • count — find and print on the screen the length of the longest non-decreasing subsequence of string s.

Subsequence of a string s is a string that can be obtained from s by removing zero or more of its elements. A string is called non-decreasing if each successive digit is not less than the previous one.

Help Petya process the requests.

佩佳非常喜欢幸运数字。众所周知,幸运数字是指十进制表示中仅包含幸运数字 4 和 7 的正整数。例如,47、744、4 是幸运数字,而 5、17、467 则不是。

佩佳带回家一个长度为 nn 的字符串 ss。该字符串仅由幸运数字组成。字符串中的字符从左到右编号,起始编号为 1。现在佩佳需要执行 mm 个如下形式的查询:

  • switch l r — 将所有下标在区间 [l,r][l, r](含端点)内的字符“翻转”(即替换为其相反数字):每个数字 4 被替换为 7,每个数字 7 被替换为 4(其中 1 ≤ l ≤ r ≤ n1 \le l \le r \le n);
  • count — 找出并输出字符串 ss 的最长非递减子序列的长度。

字符串 ss 的子序列是指通过从 ss 中删除零个或多个字符后所得到的字符串。若一个字符串中每个后续数字都不小于前一个数字,则称其为非递减字符串。

请帮助佩佳处理这些查询。

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 3·105) — the length of the string s and the number of queries correspondingly. The second line contains n lucky digits without spaces — Petya's initial string. Next m lines contain queries in the form described in the statement.

第一行包含两个整数 nn 和 mm(1 ≤ n ≤ 1061 ≤ n ≤ 10^6,1 ≤ m ≤ 3⋅1051 ≤ m ≤ 3·10^5)—— 分别表示字符串 ss 的长度和查询的数目。
第二行包含 nn 个幸运数字(不含空格)—— 这是 Petya 的初始字符串。
接下来的 mm 行,每行包含一个按题面描述格式给出的查询。

输出格式

For each query count print an answer on a single line.

对于每个查询 count,在单独一行输出答案。

输入输出样例

  • 输入#1

    2 3
    47
    count
    switch 1 2
    count

    输出#1

    2
    1
  • 输入#2

    3 5
    747
    count
    switch 1 1
    count
    switch 1 3
    count

    输出#2

    2
    3
    2

说明/提示

In the first sample the chronology of string s after some operations are fulfilled is as follows (the sought maximum subsequence is marked with bold):

  1. 47
  2. 74
  3. 74

In the second sample:

  1. 747
  2. 447
  3. 447
  4. 774
  5. 774

在第一个样例中,字符串 ss 在执行若干操作后的演变过程如下(所求的最大子序列用粗体标出):

  1. 47
  2. 74
  3. 74

在第二个样例中:

  1. 747
  2. 447
  3. 447
  4. 774
  5. 774

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

首页