#include<cstdio>
#include<algorithm>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
const int maxn=200000;

int n,c[maxn+5],ans[maxn+5],ID[maxn+5];pair<int,int> p[maxn+5];
int E,lnk[maxn+5],nxt[(maxn<<2)+5],son[(maxn<<2)+5];
int Head,Tail,que[maxn+5];bool vis[maxn+5];

void Insert(int x,int y) {for (int i=x;i<=n;i+=i&-i) c[i]=max(c[i],y);}
int Max(int x) {int MAX=0;for (int i=x;i;i-=i&-i) MAX=max(MAX,c[i]);return MAX;}
inline bool cmp(const int &a,const int &b) {return p[a]<p[b];}
#define Add(x,y) (son[++E]=(y),nxt[E]=lnk[x],lnk[x]=E)
int main(){
	scanf("%d",&n);for (int i=1;i<=n;i++) scanf("%d%d",&p[i].fr,&p[i].sc),ID[i]=i;
	sort(ID+1,ID+1+n,cmp);
	for (int i=1;i<=n;i++){
		int lst=Max(p[ID[i]].sc-1);
		if (lst) Add(ID[lst],ID[i]),Add(ID[i],ID[lst]);
		Insert(p[ID[i]].sc,i);
	}
	for (int i=1;i<=n;i++) c[i]=0;
	for (int i=n;i;i--){
		int lst=Max(n-p[ID[i]].sc);
		if (lst) Add(ID[lst],ID[i]),Add(ID[i],ID[lst]);
		Insert(n-p[ID[i]].sc+1,i);
	}
	for (int i=1;i<=n;i++){
		if (!vis[i]){
			int now=0;Head=Tail=0;que[++Tail]=i;vis[i]=true;
			while (Head!=Tail){
				int x=que[++Head];now++;
				for (int j=lnk[x];j;j=nxt[j])
					if (!vis[son[j]]) que[++Tail]=son[j],vis[son[j]]=true;
			}
			for (int i=1;i<=Tail;i++) ans[que[i]]=now;
		}
		printf("%d\n",ans[i]);
	}
	return 0;
}