#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 consecutive days: . You are sure there is some pattern in them, especially in intervals of consecutive days. Your family still does not believe you, so the only way to convince them is solid mathematics.
There are intervals of length . The -th interval starts at , so it contains the elements . 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 -th interval and the -th interval is the number of positions such that . Then we say that two intervals are -similar if and only if their distance is at most .
Now you are given the winning numbers for consecutive days and queries. Each query gives an integer . For each interval of length in the sequence, you need to compute how many other intervals are -similar to it (excluding itself).
Input Format
The first line of standard input contains two integers , representing the number of days and the interval length you want to analyze.
The second line contains integers separated by spaces, where is the winning number on day .
The third line contains one integer , the number of queries.
The next lines each contain one integer , the similarity parameter for the -th query.
Output Format
Output lines. The -th line contains integers separated by spaces, which are the answers for the -th query. The -th number in a line is the number of intervals that are -similar to the -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 :
- The first interval contains .
- The second interval contains .
- The third interval contains .
- The fourth interval contains .
- The fifth interval contains .
There are two queries.
For the first query, . The first and the third intervals, and , differ only at the second position, so their distance is . Similarly, the first and the fourth intervals, and , differ only at the first position, so their distance is . There are only these two intervals that are -similar to the first interval, so the first output number is .
For the second query, , all intervals are -similar.
Constraints
For of the data, , , , .
All testdata is divided into several subtasks with additional constraints, and each subtask contains several test points.
| Subtask | Additional Constraints | Score |
|---|---|---|
| No additional constraints |
Translated by ChatGPT 5
京公网安备 11011102002149号