#P3709. 大爷的字符串题
大爷的字符串题
Description
You are given a string . For each query, you are asked about the contribution of a sub-interval.
Definition of contribution:
Each time, pick a character from this interval (the order is up to you), then delete from the interval. Repeat until the interval is empty. You need to maintain a set .
- If is empty, your rp decreases by .
- If there exists an element in that is not less than , then your rp decreases by , and you clear .
- After that, insert into .
Since you are the boss, problems you have done usually appear in exams. After you process all characters in this interval, what is the maximum rp you can still have? The initial rp is .
Queries are independent.
Input Format
The first line contains two integers , the length of the string and the number of queries.
The next line contains numbers. The -th integer is the -th character of the given string.
Then lines follow. Each line contains two integers , meaning a query interval.
Output Format
For each query, output a single integer on one line representing the answer.
3 3
3 3 3
3 3
3 3
3 3
-1
-1
-1
Hint
Constraints
- For of the testdata, they are the sample.
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For another of the testdata, .
- For of the testdata, , , .
The testdata is as easy as a certain province’s NOI Qualifier Day 1 T2. Feel free to pass it with brute force.
It’s okay. As long as you are in a good school, even if you can only get 10 points on this problem, you can still make the team.
Translated by ChatGPT 5
京公网安备 11011102002149号