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;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010, p = 1e9 + 7;
int n;
pair<int,int> sh[MAX_N];
bool valid (int i, int j) {
if (i > j) swap(i, j);
return sh[i].second < sh[j].first || sh[j].second < sh[i].second;
}
set<int> alive;
ll trykill(int x) {
vector<int> gp[2];
queue<pair<int,int>> q;
q.emplace(x, 0);
while (q.size()) {
auto [x, g] = q.front(); q.pop();
for (int u : gp[g])
if (!valid(x, u)) return 0;
vector<int> kill;
for (int u : alive)
if (!valid(x, u))
kill.pb(u);
for (int u : kill) {
alive.erase(u);
q.emplace(u, g^1);
}
}
return 2;
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 0;i < n;++i)
cin >> sh[i].first >> sh[i].second;
sort(sh, sh + n);
if (n > 2000) return -1;
for (int i = 0;i < n;++i) alive.insert(i);
ll res = 1;
while (alive.size()) {
int x = *alive.begin();
alive.erase(x);
res = res * trykill(x) % p;
}
cout << res << '\n';
}
# | 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... |