// #pragma GCC optimize("Ofast")
// #pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define double long double
#define mkp make_pair
#define txt freopen("shortcut.in", "r", stdin), freopen("shortcut.out", "w", stdout);
const int N = 1e6 + 10, K = 29, inf = 1e16, mod = 1e9 + 7;
const double eps = 1e-6;
int t[N * 4];
int comb(int x, int y)
{
return min(x, y);
}
void build()
{
for(auto &i : t)
i = 1e9;
}
void upd(int x, int l, int r, int ind, int val)
{
if(l == r)
{
t[x] = val;
return;
}
int m = (l + r) / 2;
if(ind <= m)
upd(x * 2, l, m, ind, val);
else
upd(x * 2 + 1, m + 1, r, ind, val);
t[x] = comb(t[x * 2], t[x * 2 + 1]);
}
int get(int x, int l, int r, int tl, int tr)
{
if(tl > tr)
return 1e9;
if(l == tl && r == tr)
return t[x];
int m = (l + r) / 2;
return comb(get(x * 2, l, m, tl, min(m, tr)),
get(x * 2 + 1, m + 1, r, max(tl, m + 1), tr));
}
void solve()
{
int n;
cin >> n;
if(n == 3)
assert(0);
vector<pair<int, int>> vec;
int A[n + 5], B[n + 5];
for(int i = 1; i <= n; i++)
{
cin >> A[i] >> B[i];
vec.push_back({A[i], B[i]});
}
sort(vec.begin(), vec.end(), [](pair<int, int> a, pair<int, int> b){
return a.second < b.second;
});
// cout << "\n\n";
// set<int> S1, S2;
// for(auto i : vec)
// {
// int x = i.second;
// while(!S1.empty() && i.first > *S1.begin())
// S1.erase(S1.begin());
// while(!S2.empty() && i.first > *S2.begin())
// S2.erase(S2.begin());
// int a = (S1.empty() ? 1e9 : *S1.begin());
// int b = (S2.empty() ? 1e9 : *S2.begin());
// if(x > a && x > b)
// {
// cout << "0\n";
// return;
// }
// else if(x < a)
// S1.insert(x);
// else
// S2.insert(x);
// }
build();
int ans = 0;
for(auto i : vec)
{
int x = get(1, 1, 2 * n, i.first, i.second);
// cout << i.first << ' ' << i.second << ' ' << x << '\n';
ans += (x == 1e9 || x > i.first);
upd(1, 1, 2 * n, i.second, i.first);
}
int res = 1;
for(int i = ans; i--;)
res = res * 2 % mod;
cout << res << '\n';
}
signed main()
{
// txt;
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1;
for(; T--; solve());
}
/*
*/
# | 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... |