# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74224 | TadijaSebez | Port Facility (JOI17_port_facility) | C++11 | 3085 ms | 562856 KiB |
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 mp make_pair
#define pb push_back
const int N=2000050;
const int M=N*2;
const int mod=1e9+7;
int pos(int x){ return x<<1;}
int neg(int x){ return x<<1|1;}
struct DSU
{
int p[M];
void init(){ for(int i=0;i<N;i++) p[i]=i;}
DSU(){ init();}
int Find(int x){ return p[x]==x?x:p[x]=Find(p[x]);}
void Union(int x, int y){ p[Find(x)]=Find(y);}
} Tree;
set<pair<int,int> > st;
int l[N],r[N],id[N];
bool comp(int i, int j){ return l[i]<l[j] || l[i]==l[j] && r[i]<r[j];}
int main()
{
int n,i;
scanf("%i",&n);
for(i=1;i<=n;i++) scanf("%i %i",&l[i],&r[i]),id[i]=i;
sort(id+1,id+1+n,comp);
for(i=1;i<=n;i++)
{
int j=id[i];
set<pair<int,int> >::iterator it;
it=st.upper_bound(mp(r[j],j));
int lst=0;
if(it!=st.begin()){ it--;lst=it->second;}
for(it=st.lower_bound(mp(l[j],j));it!=st.upper_bound(mp(r[j],j));it++)
{
Tree.Union(pos(it->second),neg(j));
Tree.Union(neg(it->second),pos(j));
if(Tree.Find(pos(j))==Tree.Find(neg(lst))) break;
}
st.insert(mp(r[j],j));
}
int sol=1;
for(i=1;i<=n;i++)
{
if(Tree.Find(pos(i))==pos(i)) sol=sol*2%mod;
if(Tree.Find(pos(i))==Tree.Find(neg(i))) sol=0;
}
printf("%i\n",sol);
return 0;
}
Compilation message (stderr)
# | 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... |