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
#include<bits/stdc++.h>

using namespace std;

pair<long long,long long> T[300005];
long long D[300005];
int Win[300005];
int Wout[300005];
long long ON[300005];
long long OF[300005];
const long long M = 1000000007;
int main(){
    int n;
    cin>>n;
    long long a,r;
    for(int i=1;i<=n;i++){
        cin>>a>>r;
        T[i]={a,r};
        D[i]=r;
    }
    int j;
    for(int i=1;i<n;i++){
        j = i+1;
        r = T[i].second;
        if(T[j].first<=T[i].first+r){
            Win[j]=i;
            T[j].second=max(T[j].second,T[i].second-(T[j].first-T[i].first));
        }
    }
    for(int i=n;i>=2;i--){
        j = i-1;
        if(T[j].first>=T[i].first-D[i]){
            Wout[i]=(j);
            D[j]=max(D[j],D[i]-(T[i].first-T[j].first));
        }
    }
    ON[1]=1;
    OF[1]=1;
    long long on;
    long long of;
    for(int i=2;i<=n;i++){
        on =0;
    of = 0;
        if(Wout[i]==0 and Win[i]==0){
            ON[i]=(ON[i-1]+OF[i-1])%M;
            OF[i]=(ON[i-1]+OF[i-1])%M;
            continue;
        }
        else {
            if(Win[i]>0){
            on=(on+ON[Win[i]]+OF[Win[i]])%M;
            of=(of+OF[Win[i]])%M;
        }
        if(Wout[i]>0){
            on=(on+ON[Wout[i]])%M;
            of=(of +ON[Wout[i]]+OF[Wout[i]])%M;
        }
        ON[i]=on;
        OF[i]=of;
        }
    }
    cout<<(ON[n]+OF[n])%M;
}