#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<62)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 200000

using namespace std;

struct DSU {
  int yy[maxn+5], sy[maxn+5];
  void rest (int n) {
    for (int i = 1; i <= n; i++) {
      yy[i] = i;
      sy[i] = 1;
    }
  }
  int afla (int x) {
    int r = x, aux;
    while (yy[r] != r) r = yy[r];
    while (x != r) {
      aux = yy[x];
      yy[x] = r;
      x = aux;
    }
    return r;
  }
  void uneste (int x, int y) {
    x = afla(x);
    y = afla(y);
    if (x == y) return;
    if (sy[x] < sy[y]) swap(x, y);
    sy[x] += sy[y];
    yy[y] = x;
    sy[y] = 0;
  }
  int marime (int x) {
    return sy[afla(x)];
  }
};

DSU dsu;

struct yes {
  int x, y, ind;
};

yes v[maxn+5];

void easy () {
  int n = 10;
  cout << n << '\n';
  dsu.rest(n);
  vi u(n+1);
  int i, j, z;
  for (i = 1; i <= n; i++) u[i] = i;
  srand(time(NULL));
  random_shuffle(1+all(u));
  vector<pii> p(1, pii(0,0));
//  p.pb(pii(6,4));
//  p.pb(pii(4,3));
//  p.pb(pii(3,5));
//  p.pb(pii(7,1));
//  p.pb(pii(2,7));
//  p.pb(pii(5,2));
//  p.pb(pii(1,6));
  for (i = 1; i <= n; i++) {
    p.pb(pii(i, u[i]));
    cout << i << ' ' << u[i] << '\n';
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i != j) {
        if (p[i].fi < p[j].fi && p[i].se < p[j].se) dsu.uneste(i, j);
        if (p[i].fi > p[j].fi && p[i].se > p[j].se) dsu.uneste(i, j);
      }
  for (i = 1; i <= n; i++) cout << dsu.marime(i) << ' ';
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  easy();
//  exit(0);

  int n; cin >> n;
  dsu.rest(n);
  int i, j, z;
  for (i = 1; i <= n; i++) {
    cin >> v[i].x >> v[i].y;
    v[i].ind = i;
  }
  sort(v+1, v+n+1, [](yes &a, yes &b) { return a.y > b.y; });
  auto f = [&n, &i] () {
    set<pii> ss; ///fi = x se = ind
    stack<pii> stk; ///fi = x se = ind
    for (i = 1; i <= n; i++) {
      auto it = ss.lower_bound(pii(v[i].x, -inf));
      if (it != ss.end()) dsu.uneste(v[i].ind, it->se);
      //if (i > 1 && v[i].x < v[i-1].x) dsu.uneste(v[i].ind, v[i-1].ind);
      while (!stk.empty() && v[i].x > stk.top().fi) stk.pop();
      if (!stk.empty()) {
        dsu.uneste(v[i].ind, stk.top().se);
      }
      stk.push(pii(v[i].x, v[i].ind));
      ss.insert(pii(v[i].x, v[i].ind));
    }
  };
  f();
  sort(v+1, v+n+1, [](yes &a, yes &b) { return a.y < b.y; });
  for (i = 1; i <= n; i++) v[i].x = -v[i].x;
  f();
  sort(v+1, v+n+1, [](yes &a, yes &b) { return a.ind < b.ind; });
  for (i = 1; i <= n; i++) cout << dsu.marime(i) << '\n';
  return 0;
}
/**
10
1 6
2 7
3 5
4 10
5 2
6 3
7 8
8 9
9 4
10 1
**/


Measured memory_bytes: 16948