Problem:
Score : 300 points

Problem Statement

There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N).

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

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

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

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

Constraints

1 \leq N \leq 200,000

(x_1, x_2, \dots, x_N) is a permutation of (1, 2, \dots, N).

(y_1, y_2, \dots, y_N) is a permutation of (1, 2, \dots, N).

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

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

Sample Input 1

4
1 4
2 3
3 1
4 2

Sample Output 1

1
1
2
2

Rng can reach City 4 from City 3, or conversely City 3 from City 4.

Sample Input 2

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

Sample Output 2

3
3
1
1
2
3
2

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
struct UnionFind{
    vector<ll> parent;
    vector<ll> s;
 
    UnionFind(ll n){
        parent.resize(n);
        s.resize(n, 1);
        for(int i = 0; i < n; i++) parent[i] = i;
    }
 
    ll root(ll node){
        if(parent[node] == node){
            return node;
        } else {
            return parent[node] = root(parent[node]);
        }
    }
 
    void unite(ll x, ll y){
        ll rootx = root(x);
        ll rooty = root(y);
        if(rootx == rooty) return;
        if(s[rootx] < s[rooty]) swap(rootx, rooty);
        s[rootx] += s[rooty];
        parent[rooty] = rootx;
    }
 
    bool isSame(ll x, ll y){
        return root(x) == root(y);
    }
 
    ll size(ll x){
        return s[root(x)];
    }
};
int main(void){
    ll n;
    cin >> n;
    vector<pair<pair<ll,ll>,ll>> vecx, vecy;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        vecx.push_back({{x, y}, i});
    }

    sort(all(vecx));

    UnionFind uf(n);
    vector<pair<ll,ll>> mi(200200, {INF, INF});
    set<pair<ll,ll>> rt;
    for(ll i = 0; i < n; i++){
        for(auto &j : rt){
            if(j.first < vecx[i].first.second){
                uf.unite(vecx[i].second, j.second);
            } else {
                break;
            }
        }
        ll root = uf.root(vecx[i].second);
        if(mi[root].first > vecx[i].first.second){
            rt.erase({mi[root].first, root});
            mi[root] = {vecx[i].first.second, vecx[i].second};
            rt.insert({mi[root].first, root});
        }
    }

    rep(i, n){
        cout << uf.size(i) << endl;
    }

    
}