A8453 | Lucky Queries
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n$ and $m$ ( $1<=n<=10^{6},1<=m<=3·10^{5}$ ) — 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.
输出格式
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 $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
1. 47
2. 74
3. 74
In the second sample: 1. 747
2. 447
3. 447
4. 774
5. 774
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted