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 sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
typedef pair<int,int> ii;
typedef long long ll;
#define mod 1000000007
struct node{
int s,e,m;
ii v;
node *l,*r;
node(int _s,int _e){
s=_s;e=_e;m=(s+e)/2;v=ii(-1,-1);
if(s!=e)l=new node(s,m),r=new node(m+1,e);
}
void up(int x,int nv){
if(s==x&&e==x){
v=ii(nv,s);return;
}
if(x<=m)l->up(x,nv);
else r->up(x,nv);
v=max(l->v,r->v);
}
ii qry(int x,int y){
if(s==x&&e==y)return v;
if(y<=m)return l->qry(x,y);
if(x>m)return r->qry(x,y);
return max(l->qry(x,m),r->qry(m+1,y));
}
}*root;
struct node2{
int s,e,m,v;
node2 *l,*r;
node2(int _s,int _e){
s=_s;e=_e;m=(s+e)/2;v=0;
if(s!=e)l=new node2(s,m),r=new node2(m+1,e);
}
void up(int x){
if(s==x&&e==x){
v=1;return;
}
if(x<=m)l->up(x);
else r->up(x);
v=max(l->v,r->v);
}
int qry(int x,int y){
if(s==x&&e==y)return v;
if(y<=m)return l->qry(x,y);
if(x>m)return r->qry(x,y);
return max(l->qry(x,m),r->qry(m+1,y));
}
}*root2;
int n,a,b;
vector<ii> v;
int main(){
sf("%d",&n);
for(int i=0;i<n;++i){
sf("%d%d",&a,&b);
v.pb(a,b);
}
ll ans=1;
sort(all(v));
root=new node(1,2*n);
root2=new node2(1,2*n);
for(int i=0;i<n;++i){
ii pr=root->qry(v[i].fi,v[i].se);
if(v[i].fi<pr.fi&&pr.fi<v[i].se)pf("0\n"),exit(0);
root->up(v[i].se,pr.se);
}
for(int i=0;i<n;++i){
if(root2->qry(v[i].fi,v[i].se))ans*=2,ans%=mod;
root2->up(v[i].se);
}
pf("%lld\n",ans);
}
Compilation message (stderr)
port_facility.cpp: In function 'int main()':
port_facility.cpp:67:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | sf("%d",&n);
| ^
port_facility.cpp:69:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | sf("%d%d",&a,&b);
| ^
# | 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... |