#include <bits/stdc++.h> using namespace std; #define inf 1000000000000000007 using ll = long long; int n, rozne; ll a[300007], r[300007], wynik, dp[300007], l[300007], p[300007], l1[300007], p1[300007]; ll mod = 1000000007; queue <int> q; set <pair <ll, ll> > s; void bfs(int poz, int poz_l, int poz_p) { q.push(poz); while (!q.empty()) { int el = q.front(); q.pop(); //printf ("el - %d\n", el); //printf ("przed - %lld %lld\n", l[poz], p[poz]); ll pom_l = a[el]-r[el]; ll pom_p = a[el]+r[el]; l[poz] = min(l[poz], a[el]-r[el]); p[poz] = max(p[poz], a[el]+r[el]); //printf ("po - %lld %lld\n", l[poz], p[poz]); while (poz_l > 0 && a[poz_l] >= l[poz]) { q.push(poz_l); poz_l--; } while (poz_p <= n && a[poz_p] <= p[poz]) { q.push(poz_p); poz_p++; } } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=1; i<=n; i++) cin >> a[i] >> r[i]; for (int i=1; i<=n; i++) { l[i] = a[i]; p[i] = a[i]; bfs(i, i-1, i+1); //printf ("para - %lld %lld\n", l[i], p[i]); s.insert({l[i], p[i]}); } rozne = s.size(); dp[1] = 1; wynik = 2; int kt = 1; for (auto p: s) { l1[kt] = p.first; p1[kt] = p.second; kt++; } for (int i=2; i<=rozne; i++) { //printf ("l/p - %lld %lld\n", l1[i], p1[i]); dp[i] = 1; for (int j=1; j<i; j++) { if (p1[j] < p1[i] && l1[i] > l1[j]) { dp[i] += dp[j]; dp[i] %= mod; } } wynik += dp[i]; wynik %= mod; //printf ("dp[%d] - %lld\n", i, dp[i]); } cout << wynik << "\n"; return 0; } /* 7 12 14 15 3 26 15 56 2 62 8 82 17 88 20 11 14 20 48 17 52 1 59 18 66 12 72 4 74 12 76 13 79 14 87 18 95 19 17 4 18 6 18 7 13 10 6 19 13 21 13 27 20 31 4 43 18 46 13 56 13 64 6 67 3 73 20 74 11 90 14 98 16 */
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #include <bits/stdc++.h> using namespace std; #define inf 1000000000000000007 using ll = long long; int n, rozne; ll a[300007], r[300007], wynik, dp[300007], l[300007], p[300007], l1[300007], p1[300007]; ll mod = 1000000007; queue <int> q; set <pair <ll, ll> > s; void bfs(int poz, int poz_l, int poz_p) { q.push(poz); while (!q.empty()) { int el = q.front(); q.pop(); //printf ("el - %d\n", el); //printf ("przed - %lld %lld\n", l[poz], p[poz]); ll pom_l = a[el]-r[el]; ll pom_p = a[el]+r[el]; l[poz] = min(l[poz], a[el]-r[el]); p[poz] = max(p[poz], a[el]+r[el]); //printf ("po - %lld %lld\n", l[poz], p[poz]); while (poz_l > 0 && a[poz_l] >= l[poz]) { q.push(poz_l); poz_l--; } while (poz_p <= n && a[poz_p] <= p[poz]) { q.push(poz_p); poz_p++; } } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=1; i<=n; i++) cin >> a[i] >> r[i]; for (int i=1; i<=n; i++) { l[i] = a[i]; p[i] = a[i]; bfs(i, i-1, i+1); //printf ("para - %lld %lld\n", l[i], p[i]); s.insert({l[i], p[i]}); } rozne = s.size(); dp[1] = 1; wynik = 2; int kt = 1; for (auto p: s) { l1[kt] = p.first; p1[kt] = p.second; kt++; } for (int i=2; i<=rozne; i++) { //printf ("l/p - %lld %lld\n", l1[i], p1[i]); dp[i] = 1; for (int j=1; j<i; j++) { if (p1[j] < p1[i] && l1[i] > l1[j]) { dp[i] += dp[j]; dp[i] %= mod; } } wynik += dp[i]; wynik %= mod; //printf ("dp[%d] - %lld\n", i, dp[i]); } cout << wynik << "\n"; return 0; } /* 7 12 14 15 3 26 15 56 2 62 8 82 17 88 20 11 14 20 48 17 52 1 59 18 66 12 72 4 74 12 76 13 79 14 87 18 95 19 17 4 18 6 18 7 13 10 6 19 13 21 13 27 20 31 4 43 18 46 13 56 13 64 6 67 3 73 20 74 11 90 14 98 16 */ |