欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1473D.Program
Program
You are given a program that consists of instructions. Initially a single variable is assigned to . Afterwards, the instructions are of two types:
- increase by ;
- decrease by .
You are given queries of the following format:
- query — how many distinct values is assigned to if all the instructions between the -th one and the -th one inclusive are ignored and the rest are executed without changing the order?
Input
The first line contains a single integer () — the number of testcases.
Then the description of testcases follows.
The first line of each testcase contains two integers and () — the number of instructions in the program and the number of queries.
The second line of each testcase contains a program — a string of characters: each character is either '+' or '-' — increment and decrement instruction, respectively.
Each of the next lines contains two integers and () — the description of the query.
The sum of over all testcases doesn't exceed . The sum of over all testcases doesn't exceed .
Output
For each testcase print integers — for each query , print the number of distinct values variable is assigned to if all the instructions between the -th one and the -th one inclusive are ignored and the rest are executed without changing the order.
Note
The instructions that remain for each query of the first testcase are:
- empty program — was only equal to ;
- "
-" — had values and ; - "
---+" — had values , , , , — there are distinct values among them; - "
+--+--+" — the distinct values are , , , .
Samples
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
1
2
4
4
3
3
4
2
3
2
1
2
2
2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |