#P17139. [KOI 2026 #1] 跳跃

[KOI 2026 #1] 跳跃

Problem Description

There are NN platforms on a 2D coordinate plane, numbered from 11 to NN. Each platform can be represented as a point on the plane. For each integer ii (1≤i≤N1 \le i \le N), the coordinates of platform ii are (Xi,i)(X_i,i).

For two integers i,ji,j (1≤i,j≤N1 \le i,j \le N), you can move from platform ii to platform jj if and only if both of the following conditions are satisfied:

  • i<ji<j.
  • ∣Xi−Xj∣≤D|X_i-X_j| \le D.

Here, DD is a given constant and is a positive integer.

Write a program that, for each platform, computes the number of distinct platforms that can be reached starting from that platform after making 00 or more moves from one platform to another. Note that this number should include the starting platform itself.

Input Format

The first line contains two integers NN and DD, separated by spaces.

The second line contains NN integers X1,X2,…,XNX_1,X_2,\ldots,X_N, separated by spaces.

Output Format

Output NN integers on one line, separated by spaces. The ii-th integer represents the number of distinct platforms that can be reached starting from platform ii after making 00 or more moves from one platform to another (1≤i≤N1 \le i \le N).

6 2
3 5 4 6 1 3
6 4 3 1 2 1
6 3
1 4 8 9 10 15
2 1 3 2 1 1
3 2
1 4 7
1 1 1

Hint

Sample Explanation 1

For each platform, the platforms reachable from it are as follows:

  • Platform 11: can reach all platforms, including platform 11 itself.
  • Platform 22: can reach platforms 22, 33, 44, and 66.
  • Platform 33: can reach platforms 33, 44, and 66.
  • Platform 44: cannot reach any other platform except platform 44 itself.
  • Platform 55: can reach platforms 55 and 66.
  • Platform 66: cannot reach any other platform except platform 66 itself.

Constraints

  • All numbers in the input are integers.
  • 1≤N≤300 0001 \le N \le 300\,000.
  • 1≤D≤1091 \le D \le 10^9.
  • For each integer ii (1≤i≤N1 \le i \le N), 1≤Xi≤1091 \le X_i \le 10^9.

Subtasks

  1. (1212 points) N≤300N \le 300.
  2. (3232 points) N≤7 500N \le 7\,500.
  3. (99 points) X1≤X2≤⋯≤XNX_1 \le X_2 \le \cdots \le X_N.
  4. (2323 points) For each integer ii (1≤i≤N1 \le i \le N), Xi≤30X_i \le 30.
  5. (3333 points) D=1D=1.
  6. (4141 points) No additional constraints.

Translator's note: There are no separate testdata points for subtask 5, so subtask 6 is worth 7474 points.

Translated by ChatGPT-5.6.

Translated by ChatGPT 5