#include <bits/stdc++.h>
using namespace std;

#ifdef _LOCAL
    #include <utils/debug.hpp>
    #include <utils/random_generate.hpp>
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 42
    #define generate_string(...) 42
    #define generate_array(...) 42
    #define generate_unique_array(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void scan(){}
template <class Head, class... Tail>
void scan(Head&& head, Tail&&... tail) {
    cin >> head;
    scan(forward<Tail>(tail)...);
}

void print(){}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
    for (auto v: vs){
        cout << v;
        if (&v != &vs.back()) cout << " ";
    }
    cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

struct UnionFind {
    vl parents, set_size;
    set<ll> root_idx;
    ll n_groups;

    UnionFind(ll n){
        parents = set_size = vl(n);
        n_groups = n;
        rep(i, n){
            parents[i] = i;
            set_size[i] = 1LL;
            root_idx.insert(i);
        }
    }

    ll root_find(ll x){
        if (parents[x] == x) return x;
        return parents[x] = root_find(parents[x]);
    }

    void unite(ll x, ll y){
        // priority for x is larger than that of y
        x = root_find(x); y = root_find(y);
        if (x == y) return;
        parents[y] = x, set_size[x] += set_size[y];
        root_idx.erase(y);
        n_groups--;
    }

    // connected or not
    bool is_same(ll x, ll y){return root_find(x) == root_find(y);}
    ll size(ll x){return set_size[root_find(x)];}
};

void solve(){
    ll n, m, val, par;
    scan(n);
    vl ord(n), vs(n), ans(n);
    UnionFind uf(n);
    rep(i, n){
        ll x, y; scan(x, y);
        --x, --y;
        vs[x] = y;
        ord[x] = i;
    }

    set<pair<ll, ll>> ss;
    ss.insert({vs[0], 0});
    For(i, 1, n){
        auto it = ss.begin();
        if ((*it).first > vs[i]) {ss.insert({vs[i], i}); continue;}
        m = (*it).first;
        while (it != ss.end() && (*it).first < vs[i]){
            tie(val, par) = *it;
            ss.erase(it++);
            uf.unite(i, par);
        }
        ss.insert({m, uf.parents[i]});
    }

    rep(i, n) ans[ord[i]] = uf.size(i);
    println(ans);
}

void test(ll num = 0, bool verbose = false){
    rep(i, max(1LL, num)){
        ll t = clock();
        if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
        solve();
        if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    #ifdef _LOCAL
        test(6, true);
    #else
        ll t = 0;
        if (multiple_queries) cin >> t;
        test(t, false);
    #endif
    return 0;
}

Measured memory_bytes: 26700