#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
// Complexity: O(logN)
template <typename T>
struct BinaryIndexedTree {
    int sz;
    vector<T> data;
    BinaryIndexedTree(int sz) : sz(sz), data(sz + 1) {}
    T sum(int k) {
        // [0, k]
        T res = 0;
        for (k++; k > 0; k -= k & -k) res += data[k];
        return res;
    }
    T sum(int l, int r) {
        // [l, r)
        return sum(r - 1) - sum(l - 1);
    }
    void add(int k, T x) {
        for (k++; k <= sz; k += k & -k) data[k] += x;
    }
    // sum(a1, ... , ax)>=wを満たす最小のx(0-indexed)
    // assert(all ai is non-negative)
    int lower_bound(T w) {
        if (w <= 0) return 0;
        int x = 0;
        int k = 1;
        while ((k << 1) <= sz) k <<= 1;
        for (; k > 0; k >>= 1) {
            if (x + k <= sz && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x;
    }
};
// Time Complexity: faster than O(logN)[O(ArkInv(N))]
// UnionFind.data: if minus -> size of subtree (node is root)
// if plus -> parent of the node
struct UnionFind {
    vector<int> data;
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    int find(int x) {
        if (data[x] < 0) return x;
        return data[x] = find(data[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    int size(int x) {
        return (-data[find(x)]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};
#pragma endregion library

int main() {
    int n;
    cin >> n;
    vector<pi> ps;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        ps.emplace_back(x, y);
    }
    vector<pi> psi = ps;
    sort(all(psi));
    int mxval = 0;
    int mxidx = -1;
    UnionFind uf(n);
    BinaryIndexedTree<int> bt(n + 1);
    rrep(i, n) {
        if (mxval < psi[i].second) {
            if (mxval != 0 && bt.sum(mxval) < mxval) {
                uf.unite(i, mxidx);
            }
            mxidx = i;
            mxval = psi[i].second;
        }
        uf.unite(i, mxidx);
        bt.add(psi[i].second, 1);
    }
    int mnval = INF;
    int mnidx = -1;
    rep(i, n) {
        if (mnval > psi[i].second) {
            if (mnval != INF && bt.sum(mnval, n + 1) < n - mnval + 1) {
                uf.unite(i, mnidx);
            }
            mnidx = i;
            mnval = psi[i].second;
        }
        uf.unite(i, mnidx);
    }
    rep(i, n) {
        cout << uf.size(ps[i].first - 1) << '\n';
    }
}


Measured memory_bytes: 7956