이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e6 + 7, MOD = 1000 * 1000 * 1000 + 7;
vector <int> g[N];
int l[N], r[N];
bool intr(int i, int j) {
int a = max(l[i], l[j]);
int b = min(r[i], r[j]);
return a <= b;
}
bool in(int i, int j) {
return l[j] <= l[i] && r[i] <= r[j];
}
bool used[N], col[N];
void dfs(int u) {
used[u] = 1;
for (int v : g[u]) {
if (!used[v]) {
col[v] = col[u] ^ 1;
dfs(v);
}
}
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> l[i] >> r[i];
vector <ii> ee;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (intr(i, j) && !in(i, j) && !in(j, i)) {
g[i].app(j);
g[j].app(i);
ee.app(mp(i, j));
}
}
}
int comp = 0;
for (int i = 1; i <= n; ++i) {
if (!used[i]) {
dfs(i);
++comp;
}
}
for (auto e : ee) {
if (col[e.f] == col[e.s]) {
cout << 0 << endl;
return 0;
}
}
int ans = 1;
for (int i = 0; i < comp; ++i)
ans = (ans << 1) % MOD;
cout << ans << 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... |