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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i,b,e) for(int i = (b); i < (e); i++)
#define TRAV(x,a) for(auto &x: (a))
#define SZ(x) ((int)x.size())
#define PB push_back
#define X first
#define Y second

const int N = 3e5+5;
const int T = 1<<19;
const int mod = 1e9+7;

ll a[N], rad[N];
int lew[N], pra[N];
int tree[T*2+5];
ll n;
map<ll, int> ans;
vector<ll> jan[T*2+5];
vi sufy[T*2+5], prefy[T*2+5];

int mini(int l, int r){
    int ret = INF;
    l += T, r += T;
    while(l <= r){
        if(l&1) ret = min(ret, tree[l++]);
        if(!(r&1)) ret = min(ret, tree[r--]);
        l >>= 1, r >>= 1;
    }
    return ret;
}

void insert(int l, int val){
    l += T;
    while(l){
        tree[l] = min(tree[l], val);
        l >>= 1;
    }
}

ll id(int l, int r){
    return ((1ll*l)<<32) + r;
}

int get(ll x){
    return x & ((1ll << 32)-1);
}

int kand(int l, int val, bool jak){
    int ind = lower_bound(jan[l].begin(), jan[l].end(), id(val+1, -1)) - jan[l].begin();
    if(!jak) ind--;
    if(jak && ind != SZ(jan[l])) return sufy[l][ind];
    if(!jak && ind >= 0) return prefy[l][ind];
    return INF;
}

int que(int l, int r, int val, bool jak){
    int ret = INF;
    l += T, r += T;
    while(l <= r){
        if(l&1){
            ret = min(ret, kand(l, val, jak));
            l++;
        }
        if(!(r&1)){
            ret = min(ret, kand(r, val, jak));
            r--;
        }
        l >>= 1, r >>= 1;
    }
    return ret;
}

int solve(int l, int r){
    if(l > r) return 1;
    ll idx = id(l, r);
    if(ans.count(idx)) return ans[idx];
    // zapal go
    int wyn = solve(pra[l]+1, r);
    // nie pal go
    int spos = 1;
    int akt = l;
    while(akt < r){
        int jed = que(akt+1, r, l, 1);
        int zed = min(que(jed+1, r, l, 0), r+1);
        if(jed == INF) break;
        spos = (1ll*spos*solve(jed, zed-1)) % mod;
        akt = zed;
    }
    return ans[idx] = (wyn + spos) % mod;
}

void readInt(ll &x){
    x = 0;
    char c = getchar();
    bool negative = 0;
    while(c < 33) c = getchar();
    if(c == '-') negative = 1, c = getchar();
    while('0' <= c && c <= '9') x = 10*x + c - '0', c = getchar();
    if(negative) x *= -1;
}

void main2(){
    readInt(n);
    FOR(i, 0, n) readInt(a[i]), readInt(rad[i]);
    memset(tree, INF, sizeof(tree));
    FOR(i, 0, n){
        int ind = lower_bound(a, a+n, a[i]-rad[i]) - a;
        lew[i] = mini(ind, i);
        if(lew[i] == INF) lew[i] = i;
        insert(i, lew[i]);
    }
    memset(tree, INF, sizeof(tree));
    for(int i = n-1; i >= 0; i--){
        int ind = prev(upper_bound(a, a+n, a[i]+rad[i])) - a;
        pra[i] = -mini(i, ind);
        if(pra[i] == -INF) pra[i] = i;
        insert(i, -pra[i]);
    }
    memset(tree, INF, sizeof(tree));
    FOR(i, 0, n){
        int ind = lew[i];
        pra[i] = max(pra[i], -mini(ind, i));
        insert(i, -pra[i]);
    }
    memset(tree, INF, sizeof(tree));
    for(int i = n-1; i >= 0; i--){
        int ind = pra[i];
        lew[i] = min(lew[i], mini(i, ind));
        insert(i, lew[i]);
    }
    FOR(i, 0, n) jan[i+T] = {id(lew[i], i)};
    for(int i = T-1; i > 0; i--){
        jan[i].resize(SZ(jan[i*2]) + SZ(jan[i*2+1]));
        merge(jan[i*2].begin(), jan[i*2].end(), jan[i*2+1].begin(), jan[i*2+1].end(), jan[i].begin());
    }
    FOR(i, 1, n+T){
        int akt = INF;
        FOR(j, 0, SZ(jan[i])) akt = min(akt, get(jan[i][j])), prefy[i].PB(akt);
        akt = INF;
        for(int j = SZ(jan[i])-1; j >= 0; j--) akt = min(akt, get(jan[i][j])), sufy[i].PB(akt);
        reverse(sufy[i].begin(), sufy[i].end());
    }
    cout << solve(0, n-1) << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int tt; cin >> tt;
    // FOR(te, 0, tt)
    main2();
    return 0;
}