#define _USE_MATH_DEFINES #include <bits/stdc++.h> #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) constexpr int MOD = 1e9+7; struct Fenwick { vector<ll> s; Fenwick(int n = 0) : s(n) {} void update(int i, ll v) { for (; i < sz(s); i |= i+1) { s[i] = (s[i]+v) % MOD; } } ll query(int i) { ll v = 0; for (; i > 0; i &= i-1) { v = (v + s[i-1]) % MOD; } return v; } }; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int n; cin >> n; vector<pair<ll, ll>> mines(n); each(e, mines) cin >> e.x >> e.y; vector<Pii> elems; each(e, mines) { int first = int(lower_bound(all(mines), mp(e.x-e.y, INT64_MIN)) - mines.begin()); int last = int(lower_bound(all(mines), mp(e.x+e.y, INT64_MAX)) - mines.begin()) - 1; elems.pb({first, last}); } rep(cnt, 0, 2) { Vi left; rep(i, 0, sz(elems)) { Pii& e = elems[i]; while (!left.empty() && left.back() >= e.x) { Pii& f = elems[left.back()]; left.pop_back(); if (e.x > f.x || e.y < f.y) cnt = 0; e.x = min(e.x, f.x); e.y = max(e.y, f.y); } left.pb(i); } each(e, elems) tie(e.x, e.y) = mp(n-e.y-1, n-e.x-1); reverse(all(elems)); } Fenwick dp(n); sort(all(elems), [](Pii l, Pii r) { return mp(l.y, -l.x) < mp(r.y, -r.x); }); elems.erase(unique(all(elems)), elems.end()); each(e, elems) dp.update(e.x, dp.query(e.x)+1); ll ans = dp.query(n) + 1; ans %= MOD; if (ans < 0) ans += MOD; cout << ans << '\n'; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #define _USE_MATH_DEFINES #include <bits/stdc++.h> #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using Vi = vector<int>; using Pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) constexpr int MOD = 1e9+7; struct Fenwick { vector<ll> s; Fenwick(int n = 0) : s(n) {} void update(int i, ll v) { for (; i < sz(s); i |= i+1) { s[i] = (s[i]+v) % MOD; } } ll query(int i) { ll v = 0; for (; i > 0; i &= i-1) { v = (v + s[i-1]) % MOD; } return v; } }; int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int n; cin >> n; vector<pair<ll, ll>> mines(n); each(e, mines) cin >> e.x >> e.y; vector<Pii> elems; each(e, mines) { int first = int(lower_bound(all(mines), mp(e.x-e.y, INT64_MIN)) - mines.begin()); int last = int(lower_bound(all(mines), mp(e.x+e.y, INT64_MAX)) - mines.begin()) - 1; elems.pb({first, last}); } rep(cnt, 0, 2) { Vi left; rep(i, 0, sz(elems)) { Pii& e = elems[i]; while (!left.empty() && left.back() >= e.x) { Pii& f = elems[left.back()]; left.pop_back(); if (e.x > f.x || e.y < f.y) cnt = 0; e.x = min(e.x, f.x); e.y = max(e.y, f.y); } left.pb(i); } each(e, elems) tie(e.x, e.y) = mp(n-e.y-1, n-e.x-1); reverse(all(elems)); } Fenwick dp(n); sort(all(elems), [](Pii l, Pii r) { return mp(l.y, -l.x) < mp(r.y, -r.x); }); elems.erase(unique(all(elems)), elems.end()); each(e, elems) dp.update(e.x, dp.query(e.x)+1); ll ans = dp.query(n) + 1; ans %= MOD; if (ans < 0) ans += MOD; cout << ans << '\n'; return 0; } |