Language: C++

/*input
5 2
1 1
3 4

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>
#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int n, k;
int lft[11], rght[11];

int dp[200005];

struct data {
  // Use required attributes
 
  ll sum;
 
  // Default Values
  data() : sum(0) {};
};
 
struct SegTree {
  int N;
  vector<data> seg;
  vector<bool> cLazy;
  vector<ll> lazy;
 
  void init(int n) {
    N = n;
    seg.resize(4 * N + 5);
    cLazy.assign(4 * N + 5, false);
    lazy.assign(4 * N + 5, 0);
  }
 
  // Write reqd merge functions
  void merge(data &cur, data &l, data &r) {
    cur.sum = add(l.sum, r.sum);
  }
 
  // Handle lazy propagation appriopriately
  void propagate(int node, int L, int R) {
    if (L != R) {
      cLazy[node * 2] = 1;
      cLazy[node * 2 + 1] = 1;
      lazy[node * 2] = add(lazy[node * 2], lazy[node]);
      lazy[node * 2 + 1] = add(lazy[node * 2 + 1], lazy[node]);
    }
    seg[node].sum = add(seg[node].sum, mul((R - L + 1), lazy[node]));
    lazy[node] = 0;
    cLazy[node] = 0;
  }
 
  void build(int node, int L, int R) {
    if (L == R) {
      return;
    }
    int M = (L + R) / 2;
    build(node * 2, L, M);
    build(node * 2 + 1, M + 1, R);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  data Query(int node, int L, int R, int i, int j) {
    if (cLazy[node])
      propagate(node, L, R);
    if (j < L || i > R)
      return data();
    if (i <= L && R <= j)
      return seg[node];
    int M = (L + R) / 2;
    data left = Query(node * 2, L, M, i, j);
    data right = Query(node * 2 + 1, M + 1, R, i, j);
    data cur;
    merge(cur, left, right);
    return cur;
  }
 
  data pQuery(int node, int L, int R, int pos) {
    if (cLazy[node])
      propagate(node, L, R);
    if (L == R)
      return seg[node];
    int M = (L + R) / 2;
    if (pos <= M)
      return pQuery(node * 2, L, M, pos);
    else
      return pQuery(node * 2 + 1, M + 1, R, pos);
  }
 
  void Update(int node, int L, int R, int i, int j, int val) {
    if (cLazy[node])
      propagate(node, L, R);
    if (j < L || i > R)
      return;
    if (i <= L && R <= j) {
      cLazy[node] = 1;
      lazy[node] = val;
      propagate(node, L, R);
      return;
    }
    int M = (L + R) / 2;
    Update(node * 2, L, M, i, j, val);
    Update(node * 2 + 1, M + 1, R, i, j, val);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  void pUpdate(int node, int L, int R, int pos, int val) {
    if (cLazy[node])
      propagate(node, L, R);
    if (L == R) {
      cLazy[node] = 1;
      lazy[node] += val;
      propagate(node, L, R);
      return;
    }
    int M = (L + R) / 2;
    if (pos <= M)
      pUpdate(node * 2, L, M, pos, val);
    else
      pUpdate(node * 2 + 1, M + 1, R, pos, val);
    merge(seg[node], seg[node * 2], seg[node * 2 + 1]);
  }
 
  data query(int pos) { return pQuery(1, 1, N, pos); }
 
  data query(int l, int r) { return Query(1, 1, N, l, r); }
 
  void update(int pos, int val) { pUpdate(1, 1, N, pos, val); }
 
  void update(int l, int r, int val) { Update(1, 1, N, l, r, val); }
};

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  mod = 998244353;

  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> lft[i] >> rght[i];
  } 

  SegTree obj;
  obj.init(200005);

  obj.update(1, 1);
  // dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    // dp[i] = add(dp[i], dp[i - 1]);
    // trace(i, dp[i]);
    // if (dp[i] == 0) continue;
    for (int j = 0; j < k; j++) {
      int l = lft[j], r = rght[j];
      int x = i + l, y = min(n, i + r);
      if (x > n) continue;
      // trace(i, l, r, x, y, dp[i]);
      // dp[x] = add(dp[x], dp[i]);
      // dp[y + 1] = sub(dp[y + 1], dp[i]);
      int v = obj.query(i).sum;
      obj.update(x, y, v);
      // while (x <= y) {
      //   // trace(i, x, dp[i]);
      //   dp[x] = add(dp[x], dp[i]);
      //   x++;
      // }
      // dp[x] = add(dp[x], dp[i]);
      // dp[y + 1] = sub(dp[y + 1], dp[i]);
    }
  }

  // dp[1] = sub(dp[1], 1);

  // for (int i = 1; i <= n; i++)
  //   dp[i] = add(dp[i], dp[i - 1]);

  cout << obj.query(n).sum << endl;

  return 0;
}

Compiler output:
a.cc:114:14: error: template argument 1 is invalid
  114 |   vector<data> seg;
      |              ^
a.cc:114:14: error: template argument 2 is invalid
a.cc:126:14: error: reference to 'data' is ambiguous
  126 |   void merge(data &cur, data &l, data &r) {
      |              ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:18:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:126:14: error: 'data' has not been declared
  126 |   void merge(data &cur, data &l, data &r) {
      |              ^~~~
a.cc:126:25: error: reference to 'data' is ambiguous
  126 |   void merge(data &cur, data &l, data &r) {
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:126:25: error: 'data' has not been declared
  126 |   void merge(data &cur, data &l, data &r) {
      |                         ^~~~
a.cc:126:34: error: reference to 'data' is ambiguous
  126 |   void merge(data &cur, data &l, data &r) {
      |                                  ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:126:34: error: 'data' has not been declared
  126 |   void merge(data &cur, data &l, data &r) {
      |                                  ^~~~
a.cc:153:3: error: reference to 'data' is ambiguous
  153 |   data Query(int node, int L, int R, int i, int j) {
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:168:3: error: reference to 'data' is ambiguous
  168 |   data pQuery(int node, int L, int R, int pos) {
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:214:3: error: reference to 'data' is ambiguous
  214 |   data query(int pos) { return pQuery(1, 1, N, pos); }
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc:216:3: error: reference to 'data' is ambiguous
  216 |   data query(int l, int r) { return Query(1, 1, N, l, r); }
      |   ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:103:8: note:                 'struct data'
  103 | struct data {
      |        ^~~~
a.cc: In member function 'void SegTree::init(int)':
a.cc:120:9: error: request for member 'resize' in '((SegTree*)this)->SegTree::seg', which is of non-class type 'int'
  120 |     seg.resize(4 * N + 5);
      |         ^~~~~~
a.cc: In member function 'void SegTree::merge(int&, int&, int&)':
a.cc:127:9: error: request for member 'sum' in 'cur', which is of non-class type 'int'
  127 |     cur.sum = add(l.sum, r.sum);
      |         ^~~
a.cc:127:21: error: request for member 'sum' in 'l', which is of non-class type 'int'
  127 |     cur.sum = add(l.sum, r.sum);
      |                     ^~~
a.cc:127:28: error: request for member 'sum' in 'r', which is of non-class type 'int'
  127 |     cur.sum = add(l.sum, r.sum);
      |                            ^~~
a.cc: In member function 'void SegTree::propagate(int, int, int)':
a.cc:138:8: error: invalid types 'int[int]' for array subscript
  138 |     seg[node].sum = add(seg[node].sum, mul((R - L + 1), lazy[node]));
      |        ^
a.cc:138:28: error: invalid types 'int[int]' for array subscript
  138 |     seg[node].sum = add(seg[node].sum, mul((R - L + 1), lazy[node]));
      |                            ^
a.cc: In member function 'voi