Triple Attack
시간 제한3초메모리 제한2048 MB
정렬된 배열과 q개의 구간 질의가 주어질 때, 선택한 값 중 어떤 세 개도 폭 z 이하의 구간에 들어가지 않도록 하는 각 구간의 최대 안전 부분집합 크기를 구한다.
문제
Zeus is analyzing a replay of the fight to understand his opponent's attack patterns. The opponent has a special ability: if they land three attacks on a target within a time frame of , their third attack becomes a powerful, boosted attack.
To outplay his opponent, Zeus should not let his opponent trigger their boosted attack. Let be the multiset of timestamps, where each represents the time when the opponent's attack landed. We call to be safe if for every three timestamps such that , it holds that , where is the duration of the time frame that is given to you as an input.
Zeus has a log of timestamps, , representing when the opponent's attacks landed. The timestamps are sorted in nondecreasing order of occurrence. In other words, for all .
Zeus has intervals of interest, denoted as two integers . For each interval, Zeus wants to find the maximum number of attacks among that he could have let through: In other words, Zeus wants to find a maximum size subset of the multiset such that the subset is safe.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line contains two integers and (, ).
The second line contains integers () --- the timestamps of the opponent's attacks. It is guaranteed that the array is sorted, i.e., for all .
The third line contains a single integer ().
The next lines each contain two integers and () --- the endpoints of the interval.
It is guaranteed that the sum of over all test cases does not exceed .
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each of the queries, print a single integer --- the maximum size of a safe subset of attack timestamps in the given interval.
힌트
In the first query of the first test case, we consider the timestamps with . The subset is safe because its only triplet satisfies . It's impossible to form a safe subset of size , hence the answer to this query is .
In the first query of the second test case, we consider the timestamps with . The entire set is safe because there are no triplets. Hence the answer to this query is .
In the second query of the second test case, we consider the timestamps with .
The subset is safe because:
- For the triple , .
- For the triple , .
- For the triple , .
- For the triple , .
It's impossible to form a safe subset of size , hence the answer to this query is .