//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "avx")

#ifdef __APPLE__
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>
#else
# include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = 2e5+10, inf = 1000111222;

int ans[max_n];

pair<pii,pii> t[4*max_n];

pair<pii,pii> merge(pair<pii,pii> a,pair<pii,pii> b)
{
    pair<pii,pii> res=a;
    res.fir=min(res.fir,b.fir);
    res.sec=max(res.sec,b.sec);
    return res;
}

void upd(int v,int l,int r,int pos,bool left,pii val)
{
    if (l==r){
        if (left){
            t[v].fir=val;
        }
        else{
            t[v].sec=val;
        }
        return;
    }
    int m=(l+r)/2;
    if (pos<=m){
        upd(v*2,l,m,pos,left,val);
    }
    else{
        upd(v*2+1,m+1,r,pos,left,val);
    }
    t[v]=merge(t[v*2],t[v*2+1]);
}

pair<pii,pii> get(int v,int l,int r,int tl,int tr)
{
    if (l>tr||r<tl){
        return mp(mp(1e9,-1),mp(-1e9,-1));
    }
    if (l>=tl&&r<=tr){
        return t[v];
    }
    int m=(l+r)/2;
    return
        merge(
                get(v*2,l,m,tl,tr),
                get(v*2+1,m+1,r,tl,tr)
                );
}

int id_of_comp[max_n];
int size_of_comp[max_n];

int n;
vector<pair<int,pii> > a;

void dfs(int now,int c)
{
//    cerr<<"dfs :: "<<now<<" "<<c<<"\n";
//    cerr<<"("<<a[now].sec.fir<<" "<<a[now].sec.sec<<")"<<"\n";
    size_of_comp[c]++;
    id_of_comp[now]=c;

    upd(1,1,n,a[now].sec.fir,1,mp(1e9,-1));
    upd(1,1,n,a[now].sec.fir,0,mp(-1e9,-1));

    // check down
    while (1){
        pair<pii,pii> cur = get(1,1,n,1,a[now].sec.fir);
//        cerr<<"down :: "<<cur.fir.fir<<" "<<a[now].sec.sec<<"\n";
        if (cur.fir.fir<a[now].sec.sec){
            dfs(cur.fir.sec,c);
        }
        else{
            break;
        }
    }

    // check up
    while (1){
        pair<pii,pii> cur = get(1,1,n,a[now].sec.fir,n);
//        cerr<<"up :: "<<cur.sec.fir<<" "<<a[now].sec.sec<<"\n";
//        cerr<<"id :: "<<cur.sec.sec<<"\n";
        if (cur.sec.fir>a[now].sec.sec){
            dfs(cur.sec.sec,c);
        }
        else{
            break;
        }
    }
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    cin>>n;
    a.resize(n);
    for (int i=0;i<n;i++){
        a[i].fir=i;
        cin>>a[i].sec.fir;
        cin>>a[i].sec.sec;
    }
    sort(all(a),[&](pair<int,pii> l,pair<int,pii> r){
        return l.sec.fir<r.sec.fir;
    });
    for (int i=0;i<n;i++){
        upd(1,1,n,i+1,1,mp(a[i].sec.sec,i));
        upd(1,1,n,i+1,0,mp(a[i].sec.sec,i));
    }
    int cur_comp_id=0;
    for (int i=0;i<n;i++){
        if (!id_of_comp[i]){
            dfs(i,++cur_comp_id);
        }
    }
    for (int i=0;i<n;i++){
        int cur_ans=size_of_comp[id_of_comp[i]];
        ans[a[i].fir]=cur_ans;
    }
    for (int i=0;i<n;i++){
        cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 21616