1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
ID: syposz11
PROG: #####################
LANG: C++
*/
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int maxN=1048576;
const int N=524288;


struct p{
	int a,b;
	p(){
		a=0;b=0;
	}
	p(int x,int y){
		a=x;
		b=y;
	}
	inline bool operator<(const p &X)const{
		return a==X.a?b<X.b:a<X.a;
		}
};

vector<p> V;

struct drz{
	p W[maxN];
	inline void set(int x){
		while(x){
			W[x].a=max(W[x*2].a,W[x*2+1].a)+W[x].b;
			x/=2;
		}
	}
	inline int dod(int x,int y,int c){
		while(x<y){
			if(x&1){
				W[x].b+=c;
				set(x);
				x++;
			}
			if((y&1)^1){
				W[y].b+=c;
				set(y);
				y--;
			}
			x/=2;
			y/=2;
		}
		if(x==y){
			W[x].b+=c;
			set(y);
		}
	}
}D;

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		V.push_back(p(a,b));
		V.push_back(p(b,a));
		D.dod(a,b,1);
	}
	sort(V.begin(),V.end());
	
	
	
	
   return 0;
}