欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1843E.Tracking Segments
Tracking Segments
You are given an array consisting of zeros. You are also given a set of not necessarily different segments. Each segment is defined by two numbers and () and represents a subarray of the array .
Let's call the segment beautiful if the number of ones on this segment is strictly greater than the number of zeros. For example, if , then the segment is beautiful (the number of ones is , the number of zeros is ), but the segment is not is beautiful (the number of ones is , the number of zeros is ).
You also have changes. For each change you are given the number , which means that you must assign an element the value .
You have to find the first change after which at least one of given segments becomes beautiful, or report that none of them is beautiful after processing all changes.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers and () — the size of the array and the number of segments, respectively.
Then there are lines consisting of two numbers and () —the boundaries of the segments.
The next line contains an integer () — the number of changes.
The following lines each contain a single integer () — the index of the array element that needs to be set to . It is guaranteed that indexes in queries are distinct.
It is guaranteed that the sum of for all test cases does not exceed .
Output
For each test case, output one integer — the minimum change number after which at least one of the segments will be beautiful, or if none of the segments will be beautiful.
Note
In the first case, after first 2 changes we won't have any beautiful segments, but after the third one on a segment there will be 3 ones and only 2 zeros, so the answer is 3.
In the second case, there won't be any beautiful segments.
Samples
6
5 5
1 2
4 5
1 5
1 3
2 4
5
5
3
1
2
4
4 2
1 1
4 4
2
2
3
5 2
1 5
1 5
4
2
1
3
4
5 2
1 5
1 3
5
4
1
2
3
5
5 5
1 5
1 5
1 5
1 5
1 4
3
1
4
3
3 2
2 2
1 3
3
2
3
1
3
-1
3
3
3
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |