atcoder#ACL1A. Reachable Towns
Reachable Towns
Score : points
Problem Statement
There are cities on a 2D plane. The coordinate of the -th city is . Here and are both permuations of .
For each , find the answer to the following question:
Rng is in City . Rng can perform the following move arbitrarily many times:
- move to another city that has a smaller -coordinate and a smaller -coordinate, or a larger -coordinate and a larger -coordinate, than the city he is currently in.
How many cities (including City ) are reachable from City ?
Constraints
- is a permutation of .
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. In -th line print the answer to the question when .
4
1 4
2 3
3 1
4 2
1
1
2
2
Rng can reach City from City , or conversely City from City .
7
6 4
4 3
3 5
7 1
2 7
5 2
1 6
3
3
1
1
2
3
2