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;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MOD = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 300100;
stack<pi> S;
ll N,M,a,b;
typedef pair<ll, pi> pip;
vector<pip> V;
ll p[MAXN];
ll par(ll x){return(p[x]==x)?x:p[x]=par(p[x]);}
struct node{
ll s,e,m,v;
node *l, *r;
node (ll _s, ll _e):s(_s), e(_e){
m=(s+e)/2;v=-INF;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void up(ll x, ll val){
if (s==e){v=val;return;}
if (x<=m)l->up(x,val);
else r->up(x,val);
v=max(l->v,r->v);
}
ll query(ll x, ll y){
// cout<<x<<' '<<y<<' '<<s<<' '<<e<<'\n';
if (s==x&&e==y)return v;
if (y <= m)return l->query(x,y);
else if (x>m)return r->query(x,y);
return max(l->query(x,m), r->query(m+1,y));
}
}*root;
bool cmpa(pip x, pip y){return x.s.f<y.s.f;}
bool cmpb(pip x, pip y){return x.s.s>y.s.s;}
ll mem[MAXN];
int main(){
cin>>N;
for (ll i=0;i<N;++i){
cin>>a>>b;
V.pb(i, mp(a,b));
p[i]=i;
}
sort(ALL(V), cmpa);
M=1;
for (ll x=0;x<SZ(V);++x){
pi i=V[x].s;
for (ll y=0;y<SZ(V);++y){
pi j=V[y].s;
if (j.f<i.f&&j.s>i.f&&j.s<i.s){
p[par(x)] = par(y);
// cout<<x<<' '<<y<<'\n';
}
}
}
for(ll i=0;i<N;++i)if (par(i) == i){
M = (M*2);
if (M>= MOD)assert(0);
}
root = new node(1,2*N);
for(ll i=0;i<N;++i){
// cout<<"Ask "<<V[i].s.f<<' '<<V[i].s.s<<'\n';
ll l = root->query(V[i].s.f, V[i].s.s);
mem[V[i].f] = l;
root->up(V[i].s.s, V[i].s.s);
// cout<<"Up "<<V[i].s.s<<'\n';
}
root = new node(1,2*N);
sort(ALL(V), cmpb);
for(ll i=0;i<N;++i){
// cout<<V[i].s.f<<' '<<V[i].s.s<<'\n';
ll l = root->query(V[i].s.f, V[i].s.s);
l=abs(l);
if (l!=INF && mem[V[i].f]!=INF){
ll a = mem[V[i].f];
if (a > l){
cout<<0;
return 0;
}
}
root->up(V[i].s.f, -V[i].s.f);
}
cout<<M;
}
# | 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... |