This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
// Written by Ilia Rahbar
// #pragma GCC optimize ("O3,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target ("abm,bmi,bmi2,tbm,avx2")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define ai(x) array <int, x>
#define F first
#define S second
const int MOD = 1e9 + 7, N = 1e5 + 100;
ai(2) a[N];
int n, d[N], l[N * 2], vs[N], c, ans = 1;
set <int> s;
set <int> :: iterator itr;
vector <int> v[N];
void dfs(int inx)
{
for (auto i : v[inx])
{
if (d[i])
{
if (d[i] != 3 - d[inx])
{
cout << 0;
exit(0);
}
continue;
}
d[i] = 3 - d[inx];
dfs(i);
}
}
int32_t main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i][0] >> a[i][1];
sort(a, a+n);
for (int i = 0; i < n; i++)
{
l[a[i][0]] = i+1;
l[a[i][1]] = i+1;
}
for (int i = 1; i <= n * 2; i++)
{
if (vs[l[i]])
{
s.erase(l[i]);
itr = s.end();
while (s.size())
{
itr--;
if (*itr < l[i])
break;
v[*itr].push_back(l[i]);
v[l[i]].push_back(*itr);
if (itr == s.begin())
break;
}
}
else
{
vs[l[i]] = 1;
s.insert(l[i]);
}
}
for (int i = 1; i <= n; i++)
{
if (!d[i])
{
d[i] = 1;
dfs(i);
c++;
}
}
for (int i = 0; i < c; i++)
ans = (ans * 2) % MOD;
cout << ans;
}
# | 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... |