#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#ifdef LOCAL
#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),"] "
#define bits(x) bitset<22>(x)
#define tham getchar()
#endif

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

mt19937_64 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
//const ll mod = ;
//const ld error = ;
const ld PI = acosl(-1);

//inline ll MOD(ll x, ll m = mod){
//    ll y = x % m;
//    return (y >= 0) ? y: y+m;
//}

//const int/ll inf = ;
const int nmax = 2e5+10;
///===========================================  template  =======================================================

#define lc (id<<1)
#define rc ((id<<1)|1)

int arr[nmax];
pair<int, int> tree[4*nmax];

pair<int, int> op(pair<int, int> p, pair<int, int> q){
    if(p.first == -1) return q;
    if(q.first == -1) return p;
    return {arr[p.first] < arr[q.first]? p.first: q.first, arr[p.second] > arr[q.second]? p.second : q.second};
}

void build(int id, int l, int r)
{
    if(l == r)
    {
        tree[id] = {l, l};
        return;
    }
    int mid = (l+r)/2;
    build(lc, l, mid);
    build(rc, mid+1, r);
    tree[id] = op(tree[lc], tree[rc]);
}

pair<int, int> query(int id, int l, int r, int L, int R)
{
    if(R < l || r < L) return {-1, -1};	//Disjoint case, return identity
    if(L <= l && r <= R) return tree[id];	//Subinterval case, return value

    int mid = (l+r)/2;
    auto p = query(lc, l, mid, L, R);
    auto q = query(rc, mid+1, r, L, R);
    return op(p, q);
}

void update(int id, int l, int r, int k)
{
    if(l == r)
    {
    	tree[id] = {-1, -1};
        return;
    }

    int mid = (l+r)/2;
    if(k <= mid) update(lc, l, mid, k);
    else update(rc, mid+1, r, k);

    tree[id] = op(tree[lc], tree[rc]);
}

int comp[nmax];
int sz[nmax];
int id[nmax];


int ans[nmax];


void bfs(int root, int n){
    queue<int> q;
    q.push(root);

    update(1, 1, n, root);

    while(!q.empty()){
        int u = q.front();
        q.pop();
        comp[u] = root;
        sz[root]++;

        while(true){
            auto p = query(1, 1, n, u+1, n);
            if(p.first == -1 || arr[p.second] < arr[u]) break;
            q.push(p.second);
            update(1, 1, n, p.second);
        }

        while(true){
            auto p = query(1, 1, n, 1, u-1);
            if(p.first == -1 || arr[p.first] > arr[u]) break;
            q.push(p.first);
            update(1, 1, n, p.first);
        }
    }
}

int main(){
    FASTIO;

    int n;
    cin>>n;

    for(int i = 0; i<n; i++){
        int x, y;
        cin>>x>>y;
        id[x] = i;
        arr[x] = y;
    }

    build(1, 1, n);

    for(int i = 1; i<=n; i++){
        if(comp[i] == 0){
            bfs(i, n);
        }
    }

    for(int i = 1; i<=n; i++){
        sz[i] = sz[comp[i]];
        ans[id[i]] = sz[i];
    }

    for(int i = 0; i<n; i++){
        cout<<ans[i]<<"\n";
    }



    return 0;
}


Measured memory_bytes: 11640