#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 2e5+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
int par[MAXN],sz[MAXN];
void make_set(int s)
{
    par[s]=s;
    sz[s]=1;
}
int find_set(int s)
{
    if (par[s]==s)
        return s;
    return par[s]=find_set(par[s]);
}
void union_sets(int u,int v)
{
    u=find_set(u);
    v=find_set(v);
    if (u!=v)
    {
        if (sz[u]<sz[v])
            swap(u,v);
        par[v]=u;
        sz[u]+=sz[v];
    }
}
pii t[4*MAXN];
int a[MAXN];
void build(int v,int vl,int vr)
{
    if (vl==vr)
    {
        t[v]={a[vl],a[vl]};
        return;
    }
    int mid=((vl+vr)>>1);
    build(2*v+1,vl,mid);
    build(2*v+2,mid+1,vr);
    t[v]={min(t[2*v+1].fi,t[2*v+2].fi),max(t[2*v+1].se,t[2*v+2].se)};
}
void update(int v,int vl,int vr,int pos,int x,int y)
{
    if (vl==vr)
    {
       t[v]={x,y};
       return;
    }
    int mid=((vl+vr)>>1);
    if (pos<=mid)
        update(2*v+1,vl,mid,pos,x,y);
    else
        update(2*v+2,mid+1,vr,pos,x,y);
    t[v]={min(t[2*v+1].fi,t[2*v+2].fi),max(t[2*v+1].se,t[2*v+2].se)};
}
pii query(int v,int vl,int vr,int l,int r)
{
    if (vl>r||vr<l)
        return {INF,-1};
    if (l<=vl&&vr<=r)
        return t[v];
    int mid=((vl+vr)>>1);
    pii x=query(2*v+1,vl,mid,l,r);
    pii y=query(2*v+2,mid+1,vr,l,r);
    return {min(x.fi,y.fi),max(x.se,y.se)};
}
void solve()
{
    int n;
    cin>>n;
    vector <int> ans(n);
    vector <int> what(n);
    for (int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;
        a[x]=y;
        what[x]=i;
    }
    build(0,0,n-1);
    for (int i=0;i<n;i++)
        make_set(i);
    for (int i=0;i<n;i++)
    {
        if (a[i]==INF)
            continue;
        int x_up=i,y_up=a[i];
        int x_down=i,y_down=a[i];
        update(0,0,n-1,i,INF,-1);
        a[i]=INF;
        while (true)
        {
            bool ok=false;
            if (x_up<n)
            {
                auto to=query(0,0,n-1,x_up+1,n-1);
                if (to.se>y_up)
                {
                    ok=true;
                    int l=x_up+1,r=n-1;
                    int ind;
                    while (l<=r)
                    {
                        int mid=((l+r)>>1);
                        if (query(0,0,n-1,x_up+1,mid).se>y_up)
                            ind=mid,r=mid-1;
                        else
                            l=mid+1;
                    }
                //    cout<<"More: "<<ind<<" "<<i<<'\n';
                    union_sets(ind,i);
                    x_up=min(x_up,ind);
                    x_down=max(x_down,ind);
                    y_up=min(y_up,a[ind]);
                    y_down=max(y_down,a[ind]);
                    a[ind]=INF;
                    update(0,0,n-1,ind,INF,-1);
                }
            }
            if (x_down-1>=0)
            {
                auto to=query(0,0,n-1,0,x_down-1);
                if (to.fi<y_down)
                {
                    ok=true;
                    int l=0,r=x_down-1;
                    int ind;
                    while (l<=r)
                    {
                        int mid=((l+r)>>1);
                        if (query(0,0,n-1,mid,x_down-1).fi<y_down)
                            ind=mid,l=mid+1;
                        else
                            r=mid-1;
                    }
                  //  cout<<"Less: "<<ind<<" "<<i<<'\n';
                    union_sets(ind,i);
                    x_up=min(x_up,ind);
                    x_down=max(x_down,ind);
                    y_up=min(y_up,a[ind]);
                    y_down=max(y_down,a[ind]);
                    a[ind]=INF;
                    update(0,0,n-1,ind,INF,-1);
                }
            }
            if (!ok)
                break;
        }
    }
    for (int i=0;i<n;i++)
    {
        ans[what[i]]=sz[find_set(i)];
    }
    for (auto to:ans)
        cout<<to<<'\n';
}

int main() {
 //   ios_base::sync_with_stdio(0);
 //   cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
    _t=1;
//    cin>>_t;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 11112