#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
// const i64 smod = 998'244'353ll;

const i64 inf = mod;

const long double eps = 1e-8;

struct TCalcSegTree {
    using Type = i64;
    const Type Zero = 0;

    inline Type Combine(Type a, Type b) {
        return a + b;
    }

    i64 N = 0;
    vector<Type> St;

    TCalcSegTree() {}

    TCalcSegTree(i64 size) {
        Init(size);
    }

    void Init(i64 size) {
        N = 1;
        while (N < size) {
            N *= 2;
        }
        St.assign(N * 2, Zero);
    }

    void Set(i64 i, Type v, i64 x, i64 lx, i64 rx) {
        if (rx - lx == 1) {
            St[x] = v;
            return;
        }

        i64 m = (lx + rx) / 2;
        if (i < m) {
            Set(i, v, x * 2 + 1, lx, m);
        }
        else {
            Set(i, v, x * 2 + 2, m, rx);
        }

        St[x] = Combine(St[x * 2 + 1], St[x * 2 + 2]);
    }

    void Set(i64 i, Type v) {
        Set(i, v, 0, 0, N);
    }

    Type Calc(i64 l, i64 r, i64 x, i64 lx, i64 rx) {
        if (lx >= r || l >= rx) {
            return Zero;
        }

        if (l <= lx && rx <= r) {
            return St[x];
        }

        i64 m = (lx + rx) / 2;
        Type v1 = Calc(l, r, x * 2 + 1, lx, m);
        Type v2 = Calc(l, r, x * 2 + 2, m, rx);
        return Combine(v1, v2);
    }

    Type Calc(i64 l, i64 r) {
        return Calc(l, r, 0, 0, N);
    }
};

struct TDsu {
    vector<i64> Dsu;

    TDsu();

    TDsu(i64 size) {
        Init(size);
    }

    void Init(i64 size) {
        Dsu.resize(size);

        for (i64 i = 0; i < size; i++) {
            Dsu[i] = i;
        }
    }

    i64 FindSet(i64 v) {
        if (v == Dsu[v]) {
            return v;
        }
        return Dsu[v] = FindSet(Dsu[v]);
    }

    void UnionSets(i64 a, i64 b) {
        a = FindSet(a);
        b = FindSet(b);
        if (a != b) {
            Dsu[b] = a;
        }
    }
};


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    i64 n;
    cin >> n;

    vector<pair<i64, i64>> a(n + 1);

    for (i64 i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    vector<pair<pair<i64, i64>, i64>> z;

    for (i64 i = 1; i <= n; i++) {
        z.push_back({ a[i], i });
    }

    TDsu dsu(n + 1);

    sort(z.begin(), z.end());

    set<pair<i64, i64>> q;
    for (auto e : z) {
        auto eit = q.insert({ e.first.second, e.second }).first;
        if (eit == q.begin()) {
            continue;
        }
        auto it = q.begin();
        it++;

        while (it != eit) {
            dsu.UnionSets(q.begin()->second, it->second);
            q.erase(it++);
        }

        dsu.UnionSets(q.begin()->second, eit->second);
        q.erase(eit++);
    }

    reverse(z.begin(), z.end());

    set<pair<i64, i64>, greater<pair<i64, i64>>> p;
    for (auto e : z) {
        auto eit = p.insert({ e.first.second, e.second }).first;
        if (eit == p.begin()) {
            continue;
        }
        auto it = p.begin();
        it++;

        while (it != eit) {
            dsu.UnionSets(p.begin()->second, it->second);
            p.erase(it++);
        }

        dsu.UnionSets(p.begin()->second, eit->second);
        p.erase(eit++);
    }

    map<i64, i64> w;
    for (i64 i = 1; i <= n; i++) {
        w[dsu.FindSet(i)] += 1;
    }

    stringstream ss;
    for (i64 i = 1; i <= n; i++) {
        ss << w[dsu.FindSet(i)] << endl;
    }
    cout << ss.str();

    return 0;
}

Measured memory_bytes: 17228