This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD=1000000007;
int n;
ii arr[1000005];
vector<int> stk;
bool vis[1000005];
bool col[1000005];
struct node{
	int s,e,m;
	vector<int> v;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void update(int i,int k){
		v.pub(k);
		
		if (s==e) return;
		if (i<=m) l->update(i,k);
		else r->update(i,k);
	}
	
	int query(int i,int j){
		if (s==i && e==j){
			while (!v.empty() && vis[v.back()]) v.pob();
			if (!v.empty()) return v.back();
			else return -1;
		}
		else if (j<=m) return l->query(i,j);
		else if (m<i) return r->query(i,j);
		else return max(l->query(i,m),r->query(m+1,j));
	}
} *root=new node(0,200005);
struct node2{
	int s,e,m;
	int val=-1;
	node2 *l,*r;;
	
	node2 (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node2(s,m);
			r=new node2(m+1,e);
		}
	}
	
	void update(int i,int k){
		val=max(val,k);
		
		if (s==e) return;
		if (i<=m) l->update(i,k);
		else r->update(i,k);
	}
	
	int query(int i,int j){
		if (s==i && e==j){
			return val;
		}
		else if (j<=m) return l->query(i,j);
		else if (m<i) return r->query(i,j);
		else return max(l->query(i,m),r->query(m+1,j));
	}
} *white=new node2(0,200005),*black=new node2(0,200005);
int ans=1;
int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n;
	
	rep(x,0,n) cin>>arr[x].fi>>arr[x].se;
	sort(arr,arr+n,[](ii i,ii j){
		return i.se<j.se;
	});
	
	rep(x,0,n) root->update(arr[x].fi,x);
	
	rep(x,0,n) if (!vis[x]){
		vis[x]=true;
		stk.pub(x);
		white->update(arr[x].fi,arr[x].se);
		
		ans=2*ans%MOD;
		
		while (!stk.empty()){
			int pos=stk.back();
			stk.pob();
			
			//cout<<pos<<" "<<col[pos]<<endl;
			
			if (!col[pos]){ //white
				if (white->query(arr[pos].fi,arr[pos].se)>arr[pos].se) ans=0;
			}
			else{ //black
				if (black->query(arr[pos].fi,arr[pos].se)>arr[pos].se) ans=0;
			}
			
			while (true){
				int it=root->query(arr[pos].fi,arr[pos].se);
				if (it==-1 || arr[it].se<arr[pos].se) break;
				
				vis[it]=true;
				stk.pub(it);
				
				col[it]=!col[pos];
				
				if (!col[it]){
					white->update(arr[it].fi,arr[it].se);
				}
				else{
					black->update(arr[it].fi,arr[it].se);
				}
			}
		}
	}
	
	cout<<ans<<endl;
}
Compilation message (stderr)
port_facility.cpp: In constructor 'node::node(int, int)':
port_facility.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
port_facility.cpp: In constructor 'node2::node2(int, int)':
port_facility.cpp:72:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |