//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

class BIT{
    vector<long long> bit;
public:
    void BIT_init(long long n){
        bit.assign(n + 1, 0);
        return;
    }
    long long get_sum(int i){
        i++;
        long long res = 0;
        while(i > 0){
            res += bit[i];
            i -= i&(-i);
        }
        return res;
    }
    void add(int i, long long x){
        i++;
        while(i <= bit.size() - 1){
            bit[i] += x;
            i += i&(-i);
        }
    }
};

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<long long> siz;
    UnionFind(int N): par(N), rnk(N), siz(N){
        for(int i = 0; i < N; i++){
            par[i] = i, rnk[i] = 0, siz[i] = 1;
        }
    }
    //根
    int find(int x){
        if(par[x] == x )return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
            siz[rx] = 0;
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            siz[ry] = 0;
            if(rnk[rx] == rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    //集合が同じか
    bool same(int x, int y){
        return find(x) == find(y);
    }
    //集合の大きさ
    int size(int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vector<pair<P,int>> p(N);
    vl invplace(N);//逆向きも
    rep(i,N){
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.first--;p[i].first.second--;
        p[i].second=i;
        invplace[p[i].first.second]=p[i].second;
    }
    sort(p.begin(),p.end());
    UnionFind uf(N);
    BIT bit;
    bit.BIT_init(N);
    set<ll> x;
    ll MN=INF;
    x.insert(INF);
    rep(i,N){
        if(bit.get_sum(p[i].first.second)>=1){
            auto itr=x.begin();
            while(*itr<p[i].first.second){
                uf.unite(invplace[*itr],p[i].second);
                //cout << invplace[*itr] << ' ' << p[i].second << '\n';
                itr++;
            }
            itr=x.begin();
            while(*itr<p[i].first.second){
                if(*itr!=MN){
                    x.erase(*itr);
                    bit.add(*itr,-1);
                }
                itr++;
            }
        }
        bit.add(p[i].first.second,1);
        x.insert(p[i].first.second);
        chmin(MN,p[i].first.second);
    }
    rep(i,N){
        p[i].first.first=N-1-p[i].first.first;p[i].first.second=N-1-p[i].first.second;
        invplace[p[i].first.second]=p[i].second;
    }
    sort(p.begin(),p.end());
    /*rep(i,N){
        cout << p[i].first.first<< ' ' << p[i].first.second << ' ' << p[i].second << '\n';
    }*/
    BIT bit1;
    bit1.BIT_init(N);
    MN=INF;
    set<ll> y;
    y.insert(INF);
    rep(i,N){
        if(bit1.get_sum(p[i].first.second)>=1){
            auto itr=y.begin();
            while(*itr<p[i].first.second){
                uf.unite(invplace[*itr],p[i].second);
                //cout << invplace[*itr] << ' ' << p[i].second << '\n';
                itr++;
            }
            itr=y.begin();
            while(*itr<p[i].first.second){
                if(MN!=*itr){
                    y.erase(*itr);
                    bit1.add(*itr,-1);
                }
                itr++;
            }
        }
        bit1.add(p[i].first.second,1);
        y.insert(p[i].first.second);
        chmin(MN,p[i].first.second);
    }
    /*rep(i,N){
        cout << bit.get_sum(i) << ' ';
    }*/
    rep(i,N){
        cout << uf.size(i) << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


Measured memory_bytes: 17672