#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef
tree < int, null_type ,less<int>,
rb_tree_tag,
tree_order_statistics_node_update > ordered_set;

/*
    Operations :
    find_by_order : returns an iterator to the k-th
    largest element (counting from zero).
    order_of_key :  returns the number of items in
    a set that are strictly smaller than our item.
    # to use as a multiset just insert a pair<int,int> with unique second element, change
    int to pair<int,int> in typedef part
*/

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 2e5 + 100, inf = 1e9;

int mx[4*N], mn[4*N];
int A[N], B[N];

/// max in a range - keeps index
/// initiate a[0] with -inf

void build (int cn, int b, int e) {
    if (b == e) {
        mx[cn] = b;
        mn[cn] = b;
        return ;
    }
    int lc = 2*cn , rc = lc+1 , mid = (b+e)/2;
    build(lc,b,mid);
    build(rc,mid+1,e) ;
    if(A[mx[lc]] > A[mx[rc]]) mx[cn] = mx[lc];
    else mx[cn] = mx[rc];

    if(B[mn[lc]] < B[mn[rc]]) mn[cn] = mn[lc];
    else mn[cn] = mn[rc];
}

int max_query (int cn , int b , int e , int i ,int j) {
    if (b > j or e < i) return 0;
    if (b >= i and e <= j) {
        return mx[cn];
    }
    int lc = 2*cn , rc = lc + 1 , mid = (b+e)/2;
    int idx1 = max_query(lc, b, mid, i, j), idx2 = max_query(rc, mid+1, e, i, j);
    if(A[idx1] > A[idx2]) return idx1;
    return idx2;
}

int min_query (int cn , int b , int e , int i ,int j) {
    if (b > j or e < i or b > e) return 0;
    if (b >= i and e <= j) {
        return mn[cn];
    }
    int lc = 2*cn , rc = lc + 1 , mid = (b+e)/2;
    int idx1 = min_query(lc, b, mid, i, j), idx2 = min_query(rc, mid+1, e, i, j);
    if(B[idx1] < B[idx2]) return idx1;
    return idx2;
}

void update(int cn, int b, int e, int idx) {
    if(b == e) {
        mx[cn] = mn[cn] = idx;
        A[idx] = -inf;
        B[idx] = inf;
        return;
    }
    int lc = 2*cn, rc = lc+1, mid = b+e>>1;
    if(idx <= mid) update(lc, b, mid, idx);
    else update(rc, mid+1, e, idx);

    if(A[mx[lc]] > A[mx[rc]]) mx[cn] = mx[lc];
    else mx[cn] = mx[rc];

    if(B[mn[lc]] < B[mn[rc]]) mn[cn] = mn[lc];
    else mn[cn] = mn[rc];
}

bool vis[N];
vector<int> visited;
int idx[N], res[N];
int n;

void dfs(int u) {
//    debug(), dbg(u);
    vis[u] = true;
    int z = A[u];
    visited.push_back(u);
    update(1,1,n,u);
    while(true) {
        int idx = min_query(1,1,n,1,u);
//        debug(), dbg(u), dbg(idx), dbg(B[idx]), dbg(z);
        if(B[idx] != inf && B[idx] < z) {
            dfs(idx);
        }
        else {
            break;
        }
    }
    while(true) {
        int idx = max_query(1,1,n,u,n);
        if(A[idx] != -inf && A[idx] > z) {
            dfs(idx);
        }
        else {
            break;
        }
    }
}

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    for(int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        A[x] = B[x] = y;
        idx[x] = i;
    }
    A[0] = -inf;
    B[0] = inf;
    build(1,1,n);
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) {
            dfs(i);
            int sz = visited.size();
            for(int u : visited) {
                res[idx[u]] = sz;
            }
            visited.clear();
        }
    }
    for(int i = 1; i <= n; i++) cout << res[i] << "\n";
}





Measured memory_bytes: 21000