Page Contents

**Reachable Towns SOLUTION**

**Reachable Towns SOLUTION**

Issue Statement

There are

N

urban areas on a 2D plane. The organize of the

I

– th city is

(xi,yi).Here (x1,x2,… ,xN) and(y1,y2… ,yN) are both permuations of (1,2,… ,N)

For each k=1,2,… ,N, discover the response to the accompanying inquiry:

Rng is in City

k

. Rng can play out the accompanying move self-assertively ordinarily:

move to another city that has a littler

x

– arrange and a littler

y

– arrange, or a bigger

x

– arrange and a bigger

y

– arrange, than the city he is as of now in.

The number of urban areas (counting City

k

) are reachable from City

k

?

Limitations

1

≤

N

≤

200

,

000

(

x

1

,

x

2

,

…

,

x

N

)

is a stage of

(

1

,

2

,

…

,

N

)

.

(

y

1

,

y

2

,

…

,

y

N

)

is a stage of

(

1

,

2

,

…

,

N

)

.

All qualities in input are whole numbers.

Information

Information is given from Standard Input in the accompanying arrangement:

N

x

1

y

1

x

2

y

2

:

x

N

y

N

Yield

Print

N

lines. In

I

– th line print the response to the inquiry when

k

=

I

.

Test Input 1

Duplicate

4

1 4

2 3

3 1

4 2

Test Output 1

Duplicate

1

1

2

2

Rng can arrive at City

4

from City

3

, or alternately City

3

from City

4

.

Test Input 2

Duplicate

7

6 4

4 3

3 5

7 1

2 7

5 2

1 6

Test Output 2

Duplicate

3

3

1

1

2

3

2