Problem:
Score : 300 points

Problem Statement

There are N cities on a 2D plane. The coordinate of the i-th city is (x_i, y_i). Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N).

For each k = 1,2,\dots,N, find the answer to the following question:

Rng is in City k.
Rng can perform the following move arbitrarily many times:

move to another city that has a smaller x-coordinate and a smaller y-coordinate, or a larger x-coordinate and a larger y-coordinate, than the city he is currently in.

How many cities (including City k) are reachable from City k?

Constraints

1 \leq N \leq 200,000

(x_1, x_2, \dots, x_N) is a permutation of (1, 2, \dots, N).

(y_1, y_2, \dots, y_N) is a permutation of (1, 2, \dots, N).

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print N lines. In i-th line print the answer to the question when k = i.

Sample Input 1

4
1 4
2 3
3 1
4 2

Sample Output 1

1
1
2
2

Rng can reach City 4 from City 3, or conversely City 3 from City 4.

Sample Input 2

7
6 4
4 3
3 5
7 1
2 7
5 2
1 6

Sample Output 2

3
3
1
1
2
3
2

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

class BIT{
    vector<long long> bit;
public:
    void BIT_init(long long n){
        bit.assign(n + 1, 0);
        return;
    }
    long long get_sum(int i){
        i++;
        long long res = 0;
        while(i > 0){
            res += bit[i];
            i -= i&(-i);
        }
        return res;
    }
    void add(int i, long long x){
        i++;
        while(i <= bit.size() - 1){
            bit[i] += x;
            i += i&(-i);
        }
    }
};

class UnionFind {
public:
    vector<int> par;
    vector<int> rnk;
    vector<long long> siz;
    UnionFind(int N): par(N), rnk(N), siz(N){
        for(int i = 0; i < N; i++){
            par[i] = i, rnk[i] = 0, siz[i] = 1;
        }
    }
    //根
    int find(int x){
        if(par[x] == x )return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
            siz[ry] += siz[rx];
            siz[rx] = 0;
        }
        else{
            par[ry] = rx;
            siz[rx] += siz[ry];
            siz[ry] = 0;
            if(rnk[rx] == rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    //集合が同じか
    bool same(int x, int y){
        return find(x) == find(y);
    }
    //集合の大きさ
    int size(int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    cin >> N;
    vector<pair<P,int>> p(N);
    vl invplace(N);
    rep(i,N){
        cin >> p[i].first.first >> p[i].first.second;
        p[i].first.first--;p[i].first.second--;
        p[i].second=i;
        invplace[p[i].first.second]=p[i].second;
    }
    sort(p.begin(),p.end());
    UnionFind uf(N);
    BIT bit;
    bit.BIT_init(N);
    set<ll> x;
    x.insert(INF);
    rep(i,N){
        if(bit.get_sum(p[i].first.second)>=1){
            auto itr=x.begin();
            while(*itr<p[i].first.second){
                uf.unite(invplace[*itr],p[i].second);
                //cout << invplace[*itr] << ' ' << p[i].second << '\n';
                itr++;
            }
            itr=x.begin();
            while(*itr<p[i].first.second){
                x.erase(*itr);
                bit.add(*itr,-1);
                itr++;
            }
        }
        bit.add(p[i].first.second,1);
        x.insert(p[i].first.second);
    }
    /*rep(i,N){
        cout << bit.get_sum(i) << ' ';
    }*/
    rep(i,N){
        cout << uf.size(i) << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/