#P17137. [KOI 2026 #1] 朋友

    ID: 19480 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>二分排序2026KOI(韩国)

[KOI 2026 #1] 朋友

Problem Description

In KOI Village, there is a straight road. There are a total of NN houses on the road, and NN students numbered from 11 to NN live in these houses, with exactly one student living in each house. For each integer ii (1≤i≤N1 \le i \le N), the coordinate of the house where student ii lives is XiX_i. No two houses are located at the same coordinate.

In addition, there are NN schools in KOI Village, numbered from 11 to NN. For each integer ii (1≤i≤N1 \le i \le N), student ii attends school SiS_i.

For students ii and jj (i≠ji \ne j), if at least one of the following conditions is satisfied, then these two students are considered friends of each other:

  • The two students attend the same school, and the distance between their houses is at most K1K_1.
  • The two students attend different schools, and the distance between their houses is at most K2K_2.

Here, the distance between two houses is defined as the absolute value of the difference of their coordinates. That is, the distance between the houses of student ii and student jj is ∣Xi−Xj∣|X_i-X_j|.

Write a program to compute, for each student, the number of their friends. Note that a student is not considered a friend of themself.

Input Format

The first line contains three integers NN, K1K_1, and K2K_2, separated by spaces.

The next NN lines give the information of each student. In the ii-th of these lines, two integers XiX_i and SiS_i are given, separated by spaces (1≤i≤N1 \le i \le N).

Output Format

Output NN integers on the first line, separated by spaces. The ii-th integer represents the number of friends of student ii (1≤i≤N1 \le i \le N).

7 3 5
9 2
1 1
14 3
6 2
17 3
4 1
8 1
4 2 2 4 1 3 2
12 8 5
31 1
10 1
49 3
23 2
62 3
18 1
40 2
14 2
55 2
27 3
45 1
36 3
2 2 1 2 0 3 2 2 0 2 2 2

Hint

Constraints

  • All numbers given in the input are integers.
  • 2≤N≤500 0002 \le N \le 500\,000.
  • 1≤K1,K2≤1091 \le K_1,K_2 \le 10^9.
  • For each integer ii (1≤i≤N1 \le i \le N), 1≤Xi≤1091 \le X_i \le 10^9.
  • For any integers i,ji,j (1≤i<j≤N1 \le i<j \le N), Xi≠XjX_i \ne X_j.
  • For each integer ii (1≤i≤N1 \le i \le N), 1≤Si≤N1 \le S_i \le N.

Subtasks

  1. (2020 points) N≤3 000N \le 3\,000.
  2. (1414 points) K1,K2≤10K_1,K_2 \le 10.
  3. (2525 points) For each integer ii (1≤i≤N1 \le i \le N), Xi≤NX_i \le N and Si≤2S_i \le 2.
  4. (2121 points) S1=S2=⋯=SN=1S_1=S_2=\cdots=S_N=1.
  5. (1010 points) For each integer ii (1≤i≤N1 \le i \le N), Si≤2S_i \le 2.
  6. (1010 points) No additional constraints.

Translated by ChatGPT-5.6.

Translated by ChatGPT 5