#ACL1A. Reachable Towns

Reachable Towns

Score : 300300 points

Problem Statement

There are NN cities on a 2D plane. The coordinate of the ii-th city is (xi,yi)(x_i, y_i). Here (x1,x2,,xN)(x_1, x_2, \dots, x_N) and (y1,y2,,yN)(y_1, y_2, \dots, y_N) are both permuations of (1,2,,N)(1, 2, \dots, N).

For each k=1,2,,Nk = 1,2,\dots,N, find the answer to the following question:

Rng is in City kk. Rng can perform the following move arbitrarily many times:

  • move to another city that has a smaller xx-coordinate and a smaller yy-coordinate, or a larger xx-coordinate and a larger yy-coordinate, than the city he is currently in.

How many cities (including City kk) are reachable from City kk?

Constraints

  • 1N200,0001 \leq N \leq 200,000
  • (x1,x2,,xN)(x_1, x_2, \dots, x_N) is a permutation of (1,2,,N)(1, 2, \dots, N).
  • (y1,y2,,yN)(y_1, y_2, \dots, y_N) is a permutation of (1,2,,N)(1, 2, \dots, N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1

x2x_2 y2y_2

::

xNx_N yNy_N

Output

Print NN lines. In ii-th line print the answer to the question when k=ik = i.

4
1 4
2 3
3 1
4 2
1
1
2
2

Rng can reach City 44 from City 33, or conversely City 33 from City 44.

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