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;
int c[2000005], a[1000005], b[1000005];
stack<int> s, t;
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] >> b[i];
c[a[i]]=c[b[i]]=i;
}
for (int i=1; i<=n*2; i++)
{
if (a[c[i]]==i)
{
bool x=(s.empty() || b[c[i]]<b[s.top()]);
bool y=(t.empty() || b[c[i]]<b[t.top()]);
if (x && y)
{
s.push(c[i]);
ans=(ans*2)%mod;
}
else if (x)
s.push(c[i]);
else if (y)
t.push(c[i]);
else
{
cout << 0;
return 0;
}
}
else
{
if (s.size() && s.top()==c[i])
s.pop();
else
t.pop();
}
}
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... |