#SGM0000037. Truy vấn may mắn (Lucky Queries)
Truy vấn may mắn (Lucky Queries)
Lucky Queries
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A string contains only 4 and 7. A range can be switched, and count asks for the longest non-decreasing subsequence length.
Input
The first line contains and the second line contains . Each operation is:
switch l r: swap4and7on .count: print the length of the longest non-decreasing subsequence of the entire string.
Output
Print one line for every count command.
Subtasks
- 20 points: .
- 30 points: .
- 50 points: , .
Examples
Input
2 3
47
count
switch 1 2
count
Output
2
1
Explanation
Initially 47 is already non-decreasing, so the answer is 2. After switching the whole range, the string is 74; a longest non-decreasing subsequence then has length 1.