Ceoi 2018 3 en - ISC
Ceoi 2018 3 en - ISC
Lottery english
Input
The first line of the standard input contains two space-separated integers n and l (1 ≤ l ≤ n ≤ 10 000), the
number of days and the length of the analysed intervals. The second line contains n space-separated integers
a1 , a2 , . . . , an (1 ≤ ai ≤ 109 ), where ai is the number that was drawn on the i-th day.
The third line contains an integer q (1 ≤ q ≤ 100), the number of queries. Each of the next q lines contains
an integer kj (0 ≤ kj ≤ l), the similarity parameter for the j-th query.
Output
Print q lines. The j-th line should contain n − l + 1 space-separated integers that are the answer to the j-th
query. The i-th number in a line should be the number of other intervals that are kj -similar to the i-th interval.
Example
For the input data: the correct result is:
6 2 2 1 1 1 1
1 2 1 3 2 1 4 4 4 4 4
2
1
2
Explanation of the example: In the example above there are five intervals of length 2:
• the first interval contains the numbers 1 2
• the second contains 2 1
• the third contains 1 3
• the fourth contains 3 2
• the fifth contains 2 1
There are two queries.
The first query has k = 1. The first and the third interval — 1 2 and 1 3 — differ only on the second
position, so the distance between them is 1. Similarly, the first and fourth interval — 1 2 and 3 2 — differ
only on the first position, so the distance is 1. These are the only two intervals that are 1-similar to the first
interval, so the first printed number is 2.
In the second query we are given k = 2. All pairs of intervals are 2-similar.