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 all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int Mod = 1e9 + 7;
const int N = 2e3 + 1;
bitset <N> b[N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <ar<int,2>> a(n);
for ( auto &[l, r]: a ){
cin >> l >> r;
}
auto in = [&](int i, int j){
return a[i][0] <= a[j][0] && a[i][1] >= a[j][1];
};
sort(all(a));
for ( int i = 0; i < n; i++ ){
for ( int j = 0; j < n; j++ ){
if ( i == j ){
continue;
}
bool flg = (a[i][0] > a[j][1] || a[i][1] < a[j][0]);
flg |= in(i, j) | in(j, i);
b[i][j] = !flg;
}
}
for ( int i = 0; i < n; i++ ){
for ( int j = i + 1; j < n; j++ ){
if ( b[i][j] && (b[i] & b[j]).count() ){
return cout << "0\n", 0;
}
}
}
int ans = 1;
set <int> st;
for ( auto &[l, r]: a ){
auto it = st.lower_bound(l);
if ( !(it != st.end() && *it < r) ){
ans = ans * 2 % Mod;
}
st.insert(r);
}
cout << ans;
cout << '\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... |