CF145E.Lucky Queries

普及/提高-

通过率:0%

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 ss with the length of nn . The string only consists of lucky digits. The digits are numbered from the left to the right starting with 11 . Now Petya should execute mm queries of the following form:

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

Subsequence of a string ss is a string that can be obtained from ss 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.

输入格式

The first line contains two integers nn and mm ( 1<=n<=106,1<=m<=31051<=n<=10^{6},1<=m<=3·10^{5} ) — the length of the string ss and the number of queries correspondingly. The second line contains nn lucky digits without spaces — Petya's initial string. Next mm lines contain queries in the form described in the statement.

输出格式

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

输入输出样例

  • 输入#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 ss 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

首页