#P17134. [KOI 2026 #1] 邻居
[KOI 2026 #1] 邻居
Problem Description
In KOI Village, there is a straight road. There are a total of houses on the road. students numbered from to live in these houses, with exactly one student in each house. For an integer (), the coordinate of the house where student lives is . That is, the coordinate of student ’s house is , and the coordinate of student ’s house is .
There are two schools in KOI Village, called School and School . Each student attends exactly one of these two schools.
For students and (), if at least one of the following conditions holds, then the two students are said to be neighbors of each other:
- The two students attend the same school, and the distance between their houses is at most .
- The two students attend different schools, and the distance between their houses is at most .
Here, the distance between two different houses is defined as the larger coordinate minus the smaller coordinate. For example, the distance between the house where student lives and the house where student lives is .
Write a program to compute, for each student, the number of students who are neighbors with them. Note that a student is not considered their own neighbor.
Input Format
The first line contains three integers , , and , separated by spaces.
The second line contains integers , separated by spaces. Here, is the index of the school that student attends ().
Output Format
Output one line containing integers separated by spaces. The -th integer is the number of students who are neighbors with student ().
5 1 2
1 1 1 2 2
1 3 3 3 2
5 1 1
1 1 1 2 2
1 2 2 2 1
7 3 1
1 1 1 1 1 1 1
3 4 5 6 5 4 3
Hint
Constraints
- All numbers in the input are integers.
- .
- .
- For each integer (), .
Subtasks
| Subtask | Points | Additional Constraints |
|---|---|---|
| 。 | ||
| 。 | ||
| 。 | ||
| No additional constraints. |
Translated by ChatGPT-5.6.
Translated by ChatGPT 5