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;
const int mod=1e9+7;
pair<int, int> a[1000005];
set<pair<int, int> > s;
int p[2000005];
int f(int x)
{
return p[x]==x?x:(p[x]=f(p[x]));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ans=1;
cin >> n;
for (int i=1; i<=n; i++)
cin >> a[i].first >> a[i].second;
sort(a+1, a+n+1);
for (int i=1; i<=n*2; i++)
p[i]=i;
for (int i=1; i<=n; i++)
{
auto itr1=s.lower_bound({a[i].first, 0}), itr2=s.lower_bound({a[i].second, 0});
for (auto itr=itr1; itr!=itr2; itr++)
{
p[f(itr->second+n)]=f(i);
p[f(itr->second)]=f(i+n);
if (f(itr->second)==f(prev(itr2)->second))
break;
}
s.insert({a[i].second, i});
}
for (int i=1; i<=n; i++)
{
if (f(i)==f(i+n))
{
cout << 0;
return 0;
}
}
for (int i=1; i<=n; i++)
if (f(i)==i)
ans=ans*2%mod;
cout << ans;
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... |