이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 2000005, mod = 1000000007;
int n, a[MXN];
pii p[MXN];
int N;
bitset<MXN> b;
vector<pii> st;
void PCOUT(priority_queue<pii> &pq) {
vector<pii> v;
cout << "PQ: ";
while (pq.size()) {
cout << '<' << pq.top().fs << ' ' << pq.top().sc << "> ";
v.push_back(pq.top());
pq.pop();
}
cout << endl;
for (auto &i : v) pq.push(i);
}
void MERGE(priority_queue<pii> &a, priority_queue<pii> &b) {
if (a.size() < b.size()) swap(a, b);
while (b.size()) {
a.push(b.top());
b.pop();
}
}
void UPDATE(priority_queue<pii> &pq) {
while (pq.size() && !b[pq.top().sc]) pq.pop();
}
struct DSU {
int p[MXN], nc;
priority_queue<pii> pq[MXN];
void init(int n) {
fill(p + 1, p + n + 1, -1);
nc = n;
}
int find(int x) {
return (p[x] < 0 ? x : p[x] = find(p[x]));
}
bool onion(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
if (p[x] > p[y]) swap(x, y);
p[x] += p[y];
p[y] = x;
MERGE(pq[x], pq[y]);
nc--;
return true;
}
} dsu;
void ADD(int l, int id) {
b[id] = true;
st.push_back(mp(l, id));
// dsu.pq[id].push(mp(l, id));
}
void REMOVE(int l, int r, int id) {
b[id] = false;
while (st.size() && st.back().fs >= l) {
auto [l2, id2] = st.back();
if (id2 != id) {
dsu.onion(id, id2 + n);
dsu.onion(id + n, id2);
}
st.pop_back();
}
UPDATE(dsu.pq[dsu.find(id)]);
if (dsu.pq[dsu.find(id)].size()) st.push_back(dsu.pq[dsu.find(id)].top());
UPDATE(dsu.pq[dsu.find(id + n)]);
if (dsu.pq[dsu.find(id + n)].size()) st.push_back(dsu.pq[dsu.find(id + n)].top());
}
int POW(int a, int b) {
int ans = 1;
for (int i = 1 << 20; i > 0; i >>= 1) {
ans = ans * ans % mod;
if (i & b) ans = ans * a % mod;
}
return ans;
}
int miku() {
cin >> n;
N = n * 2;
dsu.init(N);
FOR(i, 1, n + 1) {
cin >> p[i].fs >> p[i].sc;
a[p[i].fs] = i;
a[p[i].sc] = -i;
dsu.pq[i].push(mp(p[i].fs, i));
}
FOR(i, 1, N + 1) {
if (a[i] > 0) {
ADD(i, a[i]);
} else {
REMOVE(p[-a[i]].fs, p[-a[i]].sc, -a[i]);
}
}
FOR(i, 1, n) if (dsu.find(i) == dsu.find(i + n)) return 0;
return POW(2, dsu.nc / 2);
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
cout << miku() << '\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... |