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>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e6+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
set<ll> ck[3],idx;
ll n,x[N],y[N],g[N],col[N],ans=1;
vector<pair<pll,ll> > ed;
vector<ll> v[N/2];
ll find(ll nd){
idx.erase(x[nd]);idx.erase(y[nd]);
for(ll i=*idx.lwb(x[nd]);i<y[nd];i=*idx.lwb(i+1)){
return g[i];
}
return 0;
}
void DFS(ll nd,ll pa){
for(auto i:v[nd]){
if(i==pa)continue;
col[i]=3-col[nd];
DFS(i,nd);
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
idx.insert(2*n+1);idx.insert(0);
REP1(i,n){
idx.insert(i*2-1);idx.insert(i*2);
cin>>x[i]>>y[i];
ed.pb(mp(mp(x[i],y[i]),i));
g[x[i]]=g[y[i]]=i;
}
sort(ed.begin(),ed.end(),[](pair<pll,ll> A,pair<pll,ll> B){
if(A.X.Y-A.X.X!=B.X.Y-B.X.X)return (A.X.Y-A.X.X<B.X.Y-B.X.X);
return (A.X.X<B.X.X);
});
for(auto i:ed){
ll id=find(i.Y);
if(!id)continue;
v[id].pb(i.Y);v[i.Y].pb(id);
}
REP1(i,n){
if(!col[i]){
ans=ans*2%MOD;
col[i]=1;
DFS(i,0);
}
}
sort(ed.begin(),ed.end());
for(auto i:ed){
int ty=col[i.Y];
if(ck[ty].lwb(i.X.X)!=ck[ty].end()&&*ck[ty].lwb(i.X.X)<i.X.Y){
cout<<"0\n";return 0;
}
ck[ty].insert(i.X.Y);
}
cout<<ans<<"\n";
return 0;
}
# | 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... |