이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
pair<int, int> a[1000000];
int cmp[1000000], cnt;
int find(int A) {
while (A != cmp[A]) cmp[A] = cmp[cmp[A]], A = cmp[A];
return A;
}
bool onion(int A, int B) {
A = find(A), B = find(B);
if (A == B) return false;
cmp[A] = B;
cnt--;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
FOR(i, 0, n) cin >> a[i].first >> a[i].second;
sort(a, a + n);
cnt = n;
iota(cmp, cmp + n, 0);
set<pair<int, int>> s;
FOR(i, 0, n) {
while (s.size() && (*s.begin()).first < a[i].first) s.erase(s.begin());
for (pair<int, int> j : s) {
if (j.first > a[i].second) break;
if (!onion(i, j.second)) return cout << "0\n", 0;
}
s.insert({a[i].second, i});
}
ll ans = 1;
FOR(i, 0, cnt) ans = (ans * 2) % MOD;
cout << ans << '\n';
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... |