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 pair<ll, ll> ii;
#define REP(i, n) for(int i = 0;i < n;i ++)
#define REP1(i, n) for(int i = 1;i <= n;i ++)
#define FILL(i, n) memset(i, n, sizeof(i))
#define X first
#define Y second
#define pb push_back
#define SZ(_a) ((int)(_a).size())
#define ALL(_a) (_a).begin(), (_a).end()
#ifdef brian
#define IOS()
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...t>void _do(T &&x, t &&...X){cerr<<x<<", ";_do(X...);}
#define debug(...) {\
fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif
const ll MAXn = 1e6 + 5;
const ll INF = ll(1e18);
const ll MOD = 1000000007;
vector<ll> v[MAXn];
ll in[MAXn], out[MAXn], vis[MAXn], ev[2 * MAXn];
ll n;
bool chk()
{
vector<ll> a, b;
REP1(i, 2 * n)
{
if(ev[i] < 0)
{
if(vis[-ev[i]])
{
if(b.back() != -ev[i])return 0;
else b.pop_back();
}
else
{
if(a.back() != -ev[i])return 0;
else a.pop_back();
}
}
else
{
if(vis[ev[i]])b.pb(ev[i]);
else a.pb(ev[i]);
}
}
return 1;
}
inline ll inter(ll i,ll j)
{
return in[i] < in[j] && in[j] < out[i] && out[i] < out[j];
}
void dfs(ll now)
{
REP1(i, n)if(vis[i] == -1 && (inter(i, now) || inter(now, i)))
{
vis[i] = !vis[now];
dfs(i);
}
}
int main(){
IOS();
cin>>n;
REP1(i, n)cin>>in[i]>>out[i], ev[in[i]] = i, ev[out[i]] = -i;
ll ct = 0;
FILL(vis, -1);
REP1(i, n)if(vis[i] == -1)
{
ct ++;
dfs(i);
}
debug(ct);
if(!chk())cout<<0<<endl;
else
{
ll tt = 1;
REP1(i, ct)tt = tt * 2 % MOD;
cout<<tt<<endl;
}
}
# | 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... |