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 all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=1e6+9;
const long long du=1e9+7;
pii a[maxn];
long long pw[maxn];
int mx[maxn*8];
int pos[maxn*2];
int st[maxn*8];
int f[maxn*2];
int findset(int u){
if (f[u]<0)return u;
return f[u]=findset(f[u]);
}
void unite(int u,int v){
if (u==0||v==0)return;
u=findset(u),v=findset(v);
if (u==v)return ;
if (f[u]>f[v])swap(u,v);
f[u]+=f[v];
f[v]=u;
}
void up(int id,int l,int r,int u,int v,int val){
if (l>v||r<u||u>v)return;
if (u<=l&&r<=v){
if (val>abs(st[id])&&st[id]!=0){
unite(val,abs(st[id]));
//cout<<val<<" "<<l<<" "<<r<<'\n';
}
mx[id]=max(mx[id],val);
return;
}
int mid=(l+r)/2;
up(id*2,l,mid,u,v,val);
up(id*2+1,mid+1,r,u,v,val);
}
void solve(int id,int l,int r){
int mid=(l+r)/2;
if (l==r)return;
solve(id*2,l,mid);
solve(id*2+1,mid+1,r);
int lst=0;
for1(i,l,r){
if (pos[i]<=mx[id]){
unite(lst,pos[i]);
lst=max(lst,pos[i]);
}
}
unite(lst,mx[id]);
}
void update(int id,int l,int r,int u,int val){
if (l>u||r<u)return;
if (l==r){
st[id]=val;
return;
}
int mid=(l+r)/2;
update(id*2,l,mid,u,val);
update(id*2+1,mid+1,r,u,val);
st[id]=max(st[id*2],st[id*2+1]);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int n;
cin>>n;
for1(i,1,n)cin>>a[i].fi>>a[i].se;
sort(a+1,a+1+n);
pw[0]=1;
for1(i,1,n)pw[i]=(pw[i-1]*2)%du;
for1(i,1,n){
pos[a[i].se]=i;
}
set<int>num;
set<int>::iterator it;
for1(i,1,2*n)f[i]=-1;
for1(i,1,2*n)update(1,1,2*n,i,-4*n-1);
for1(i,1,n){
update(1,1,2*n,a[i].se,-i-n);
up(1,1,2*n,a[i].fi,a[i].se,i+n);
}
solve(1,1,2*n);
for1(i,1,n){
if (findset(i)==findset(i+n)){
cout<<0;
return 0;
}
}
int cnt=0;
for1(i,1,n){
if (f[i]<0)cnt++;
}
cout<<pw[cnt];
}
# | 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... |