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 F first
#define S second
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
int mul(int a, int b) {
return 1ll*a*b%mod;
}
int pw(int a, int b) {
int out = 1;
while (b) {
if (b&1) out = mul(out, a);
a = mul(a,a);
b>>=1;
}
return out;
}
const int N = 1e6 + 50;
int n, L[N], R[N], c[N], cnt;
bool bad;
vector<int> adj[N];
void dfs(int u) {
for (int v:adj[u]) {
if (!c[v]) {
c[v] = 3-c[u];
dfs(v);
}
else if (c[v] == c[u]) {
bad = 1;
}
}
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> L[i] >> R[i];
}
for (int u = 1; u <= n; u++) {
for (int v = 1; v <= n; v++) {
if (L[u] < L[v] && L[v] < R[u] && R[u] < R[v]) {
adj[u].push_back(v), adj[v].push_back(u);
}
}
}
for (int u = 1; u <= n; u++) {
if (!c[u]) {
c[u] = 1;
cnt++;
dfs(u);
}
}
cout << (bad? 0: pw(2, cnt)) << endl;
}
int main() {
solve();
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... |