#P6360. [CEOI 2018] Lottery

[CEOI 2018] Lottery

Description

Please note the special memory limit.

For a long time, you have been a loyal fan of Bytelotto, but your family has always told you that all such games are a waste of money. You think this is surely because they lack skill. You have a great plan, and everyone will soon see you win the game.

There are many types of games, and you are interested in one of them: Bitlotto. The rules are simple: every day, one number is drawn at random as the winning number. You recorded the winning numbers for nn consecutive days: a1,a2,,ana_1, a_2, \ldots, a_n. You are sure there is some pattern in them, especially in intervals of ll consecutive days. Your family still does not believe you, so the only way to convince them is solid mathematics.

There are nl+1n - l + 1 intervals of length ll. The ii-th interval starts at ii, so it contains the elements ai,ai+1,,ai+l1a_i, a_{i+1}, \ldots, a_{i+l-1}. Define the distance between two intervals as the number of positions where the numbers at the corresponding positions are different. Formally, the distance between the xx-th interval and the yy-th interval is the number of positions i (0i<l)i\ (0 \le i < l) such that ax+iay+ia_{x+i} \ne a_{y+i}. Then we say that two intervals are kk-similar if and only if their distance is at most kk.

Now you are given the winning numbers for nn consecutive days and qq queries. Each query gives an integer kjk_j. For each interval of length ll in the sequence, you need to compute how many other intervals are kjk_j-similar to it (excluding itself).

Input Format

The first line of standard input contains two integers n,ln, l, representing the number of days and the interval length you want to analyze.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n separated by spaces, where aia_i is the winning number on day ii.

The third line contains one integer qq, the number of queries.

The next qq lines each contain one integer kjk_j, the similarity parameter for the jj-th query.

Output Format

Output qq lines. The jj-th line contains nl+1n - l + 1 integers separated by spaces, which are the answers for the jj-th query. The ii-th number in a line is the number of intervals that are kjk_j-similar to the ii-th interval, excluding itself.

6 2
1 2 1 3 2 1
2
1
2
2 1 1 1 1
4 4 4 4 4

Hint

Sample Explanation

The whole sequence has five intervals of length 22:

  • The first interval contains 11 22.
  • The second interval contains 22 11.
  • The third interval contains 11 33.
  • The fourth interval contains 33 22.
  • The fifth interval contains 22 11.

There are two queries.

For the first query, k=1k = 1. The first and the third intervals, 11 22 and 11 33, differ only at the second position, so their distance is 11. Similarly, the first and the fourth intervals, 11 22 and 33 22, differ only at the first position, so their distance is 11. There are only these two intervals that are 11-similar to the first interval, so the first output number is 22.

For the second query, k=2k = 2, all intervals are 22-similar.

Constraints

For 100%100\% of the data, 1n1041 \le n \le 10^4, 1ai1091 \le a_i \le 10^9, 1q1001 \le q \le 100, 0kjl0 \le k_j \le l.

All testdata is divided into several subtasks with additional constraints, and each subtask contains several test points.

Subtask Additional Constraints Score
11 n300n \le 300 2525
22 n2000n \le 2000 2020
33 q=1,k1=0q = 1, k_1 = 0
44 q=1q = 1 1515
55 No additional constraints 2020

Translated by ChatGPT 5