Language: C++

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 998244353LL;

// @category セグメント木 (Segment Tree)
// @title セグメント木 (Segment Tree)
// 抽象 SegmentTree (0-indexed・一点更新・区間取得)
template <typename MonoidType>
struct SegmentTree {
    using Function = function< MonoidType(MonoidType, MonoidType) >;

    // node, identity element
    int n;
    vector<MonoidType> node;
    MonoidType E0;

    // update / combine function
    Function upd_f, cmb_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    SegmentTree() {}
    SegmentTree(int n_, MonoidType E0_,
                Function upd_f_, Function cmb_f_,
                vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), upd_f(upd_f_), cmb_f(cmb_f_) {
        build(n_, v);
    }

    // update k-th element (applied value: x)
    void update(int k, MonoidType x) {
        k += n - 1;
        node[k] = upd_f(node[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    // range query for [a, b)
    // 非再帰のアイデア: http://d.hatena.ne.jp/komiyam/20131202/1385992406
    MonoidType query(int a, int b) {
        MonoidType vl = E0, vr = E0;
        for(int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
            if(l & 1) vl = cmb_f(vl, node[(l++)-1]);
            if(r & 1) vr = cmb_f(node[(--r)-1], vr);
        }
        return cmb_f(vl, vr);
    }
};


int main() {
    int N; scanf("%d", &N);
    vector< pair<int, int> > seg;
    vector<int> pos;
    for(int i=0; i<N; i++) {
        int X, D;
        scanf("%d%d", &X, &D);
        pos.emplace_back(X);
        pos.emplace_back(X + D - 1);
        pos.emplace_back(X + D);
        seg.emplace_back(X, D);
    }
    sort(seg.begin(), seg.end());
    sort(pos.begin(), pos.end());
    pos.erase(unique(pos.begin(), pos.end()), pos.end());
    
    int M = pos.size();
    SegmentTree<int> segtree(M, -INF,
                             [](int a, int b) { return max(a, b); },
                             [](int a, int b) { return max(a, b); });

    // 根は N
    vector<int> parent(N+1, -1);
    seg.emplace_back(INF, INF);
    for(int i=N-1; i>=0; i--) {
        int X, D; tie(X, D) = seg[i];
        int l = lower_bound(pos.begin(), pos.end(), X) - pos.begin();
        int r = lower_bound(pos.begin(), pos.end(), X+D) - pos.begin();
        int v = max(segtree.query(l, r), X+D-1);
        segtree.update(l, v);
        parent[i] = upper_bound(seg.begin(), seg.end(), make_pair(v, INF)) - seg.begin();
        fprintf(stderr, "X = %d, D = %d\n", X, D);
        fprintf(stderr, "v = %d, parent %d = %d\n", v, i, parent[i]);
    }
    vector< vector<int> > G(N+1);
    for(int i=0; i<N; i++) {
        if(parent[i] < 0) continue;
        G[ parent[i] ].emplace_back(i);
    }

    vector<ll> ans1(N+1), ans2(N+1);
    auto dfs = [&](auto&& f, int cur) -> void {
        ans2[cur] = 1;
        for(auto to : G[cur]) {
            f(f, to);

            int coeff = 3;
            if(i < N) (ans1[cur] += ans1[to] + ans2[to]) %= MOD;
            (ans2[cur] += ans1[to]) %= MOD;
        }
    };
    dfs(dfs, N);
    cout << ans[N] << endl;
    return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:150:16: error: 'i' was not declared in this scope
  150 |             if(i < N) (ans1[cur] += ans1[to] + ans2[to]) %= MOD;
      |                ^
a.cc: In function 'int main()':
a.cc:155:13: error: 'ans' was not declared in this scope; did you mean 'ans2'?
  155 |     cout << ans[N] << endl;
      |             ^~~
      |             ans2