#P16545. [EGOI 2026] 狐狸家族 / Fox Families

[EGOI 2026] 狐狸家族 / Fox Families

Problem Description

Recently, a large area of the Alps has been designated as a nature reserve.

At first, there were no foxes in the reserve. However, thanks to continuous protection measures, the fox population in the reserve has been recovering day by day. Every day, one new fox arrives.

Biologist Simona is observing this recovery process, and she is very interested in the number of distinct families formed by the foxes at any point in time. Simona knows that each fox ii has a hunting territory, which can be represented by a segment [Li,Ri][L_i, R_i], where Li<RiL_i < R_i. These territories may overlap and may even contain one another.

According to her research, Simona knows that if, for two foxes ii and jj, one of their hunting territories is nested inside the other (that is, Li≤Lj<Rj≤RiL_i \leq L_j < R_j \leq R_i or Lj≤Li<Ri≤RjL_j \leq L_i < R_i \leq R_j), then they are direct relatives.

Two foxes belong to the same family if and only if they are either direct relatives, or they are connected by a chain of foxes where each adjacent pair are direct relatives. Formally, two foxes aa and bb belong to the same family if and only if there exists a sequence of foxes c0,c1,…cm−1c_0, c_1, \dots c_{m-1} such that a=c0a = c_0 and b=cm−1b = c_{m-1}, and for every 0≤i<m−10 \leq i < m-1, cic_i and ci+1c_{i+1} are direct relatives.

Fox ii (0≤i≤N−10 \leq i \leq N-1) arrives on day ii and stays in the reserve from then on, permanently keeping the same hunting territory [Li,Ri][L_i, R_i]. The arrival of each fox may or may not change the family relations. After each day, Simona wants to know the number of fox families that exist after fox ii arrives.

Input Format

The first line of input contains an integer NN, the number of days. The next NN lines each contain two integers LiL_i and RiR_i, describing the hunting territory of fox ii.

Output Format

Output NN lines. Line ii (for 0≤i≤N−10 \leq i \leq N-1) should contain an integer, the number of fox families that exist after fox ii arrives.

4
1 4
3 6
3 4
6 7
1
2
1
2
6
0 1
1 2
2 3
3 4
4 5
2 4
1
2
3
4
5
4
5
0 5
1 4
2 7
3 6
4 5
1
1
2
2
1

Hint

Sample Explanation

The first sample satisfies the constraints of subtasks 1, 2, and 5. The second sample satisfies the constraints of subtasks 1, 2, 3, and 5. The third sample satisfies the constraints of subtasks 1, 2, 4, and 5.

First sample. After the first fox arrives, there is one family. After the second fox arrives, there are two families, because [1,4][1, 4] and [3,6][3, 6] overlap but neither territory contains the other. Then, the fox with territory [3,4][3, 4] arrives: it is contained in both [1,4][1, 4] and [3,6][3, 6], so these two families merge, and the number of families is now 11. Finally, the fox with territory [6,7][6, 7] neither contains any previous territory nor is contained in them, so it forms a new family, and the number of families is now 22.

:::align{center} :::

Constraints

  • 1≤N≤100 0001 \leq N \leq 100\ 000.
  • 0≤Li<Ri≤200 0000 \leq L_i < R_i \leq 200\ 000.
  • For any two territories, (Li,Ri)(L_i, R_i) will not be repeated.

Scoring

Your program will be tested on testdata divided into several subtasks. To get the score for a subtask, you must solve all the testdata in that subtask correctly.

  • Subtask 00 [00 points]: Samples.
  • Subtask 11 [1010 points]: N≤100N \le 100.
  • Subtask 22 [1515 points]: N≤2000N \le 2000.
  • Subtask 33 [1616 points]: Ri−Li≤2R_i - L_i \le 2.
  • Subtask 44 [2323 points]: Li<Li+1L_i < L_{i+1}.
  • Subtask 55 [3636 points]: No additional constraints.

Translated by ChatGPT 5