Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,541 Bytes
91a79e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<p>   
For this problem, a <i>possible median</i> is defined as: The median value of a set containing an odd number of values. -or- One of all the integers between, but not including, the two median values of a set containing an even number of values.<br><b>Examples:</b> 3 is the only possible median of the set (1, 5, 3, 2, 4).  2, 3 and 4 are all of the possible median values for the set (5, 1).  There 
are <b>no</b> possible median values for the set (1, 2, 3, 4), since there are no integers between 2 and 3.

<p>

You are given an array <b>A</b> of <b>N</b> unique nonnegative integers, all of which are &lt; <b>N</b> (i.e. a permutation of the numbers 0...<b>N-1</b>), where 3 &le; <b>N</b> &le; 200,000.  You are
 also given a length <b>L</b> (1 &le; <b>L</b> &le; <b>N</b>).  Additionally, you are given <b>Q</b> (1 &le; <b>Q</b> &le; 200,000) queries, each containing a number <b>x</b> (0 &le; <b>x</b> &lt; N) 
and two indices <b>i</b> and <b>j</b> (0 &le; <b>i</b> &lt; <b>j</b> &le; <b>N</b>).

<p>

Each query returns TRUE if and only if there exists at least one subrange, of at least <b>L</b> elements, of the range <b>A[i]</b>...<b>A[j-1]</b> (where the array indices start at 0), with <b>x</b> as a possible median.  In other words, the answer is TRUE precisely when there exist <b>a</b>, <b>b</b> with <b>i</b> &le; <b>a</b> &lt; <b>b</b> &lt; <b>j</b> with <b>b</b> - <b>a</b> &ge; <b>L</b> - 
1 and with <b>A[a]</b>...<b>A[b]</b> having <b>x</b> as a possible median.

<p>

You wish to determine the number of queries which will return TRUE.


<h3>Input</h3>
<p>

The first line contains a positive integer <b>T</b> (1 &le; <b>T</b> &le; 20), the number of test cases.  <b>T</b> test cases follow.

<p>
The first line of each test case consists of a single integer, <b>N</b>.  The next line consists of <b>N</b> space-separated integers, the <b>A[i]</b>.  The line after that contains two space-separate
d integers, <b>L</b> and <b>Q</b>.

<p>

Each of the remaining <b>Q</b> lines in the test case contains three space-separated integers, <b>x</b>, <b>i</b> and <b>j</b>.

<p>

These inputs are all integers, and will be input in decimal form, with no leading zeros, and no decimal points.

<h3>Output</h3>
<p>

For each of the test cases numbered in order from 1 to T, output "Case #", followed by the case number, followed by ": ", followed by a single integer, the number of passing queries.

<p>

These outputs are all integers, and must be output in decimal form, with no leading zeros, and no decimal points.