alexjercan/bugnet huggingface dataset:
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

// constexpr const int mod = 1000000007;
constexpr const int mod = 998244353;
class mint {
public:
  long long x;
  constexpr mint(long long x = 0) noexcept : x((x % mod + mod) % mod) {}
  constexpr int getmod() { return mod; }
  constexpr mint operator-() const noexcept { return mint(-x); }

  constexpr mint &operator+=(const mint &a) noexcept {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator-=(const mint &a) noexcept {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  constexpr mint &operator*=(const mint &a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  constexpr mint &operator/=(const mint &a) noexcept {
    return (*this) *= a.inv();
  }

  constexpr mint operator+(const mint &a) const noexcept {
    return mint(*this) += a;
  }
  constexpr mint operator-(const mint &a) const noexcept {
    return mint(*this) -= a;
  }
  constexpr mint operator*(const mint &a) const noexcept {
    return mint(*this) *= a;
  }
  constexpr mint operator/(const mint &a) const noexcept {
    return mint(*this) /= a;
  }

  constexpr mint inv() const noexcept { return pow(mod - 2); }
  constexpr mint pow(long long t) const noexcept {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  friend istream &operator>>(istream &is, mint &a) noexcept {
    return is >> a.x;
  }
  friend ostream &operator<<(ostream &os, const mint &a) noexcept {
    return os << a.x;
  }
};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];

  vector<mint> dp(n + 1);
  vector<mint> dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, k, l, r;
  ll mod = 998244353;
  cin >> n >> k;
  vector<ll> vec;
  rep(i, k) {
    cin >> l >> r;
    for (ll i = l; i <= r; i++)
      vec.push_back(i);
  }
  sort(vec.begin(), vec.end());

  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (ll i = 1; i < n; i++) {
    if (dp[i] > 0) {
      for (auto d : vec) {
        if (i + d <= n) {
          dp[i + d] = (dp[i + d] + dp[i]) % mod;
        } else {
          break;
        }
      }
    }
  }
  // rep(i, n + 1) printf("%d%c", dp[i], (i == n ? '\\n' : ' '));
  cout << dp[n] << endl;
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;

  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }

  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);

  V[0] = 1;
  int64_t LRC[10];
  for (size_t i = 0; i < 10; ++i) {
    LRC[i] = 0;
  }

  for (int64_t i = 1; i < N; ++i) {
    for (int64_t j = 0; j < LR.size(); ++j) {
      if (i - LR[j].second - 1 >= 0) {
        LRC[j] -= V[i - LR[j].second - 1];
      }
      if (i - LR[j].first >= 0) {
        LRC[j] += V[i - LR[j].first];
      }
    }
    for (int64_t j = 0; j < LR.size(); ++j) {
      V[i] += LRC[j];
      V[i] %= 998244353;
    }
  }

  std::cout << (V[N - 1] % 998244353) << std::endl;

  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int64_t N, K;
  std::cin >> N >> K;
  std::vector<std::pair<int64_t, int64_t>> LR;

  for (size_t k = 0; k < K; ++k) {
    int64_t L, R;
    std::cin >> L >> R;
    LR.emplace_back(L, R);
  }

  std::vector<int64_t> V;
  V.resize(2 * 100000, 0);

  V[0] = 1;

  for (int64_t i = 1; i < N; ++i) {
    for (auto &lr : LR) {
      for (int64_t j = lr.first; j <= lr.second && i - j >= 0; ++j) {
        V[i] += V[i - j];
      }
    }
  }

  std::cout << (V[N - 1] % 998244353) << std::endl;

  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

#include <bits/stdc++.h>
using namespace std;

#define trav(a, A) for (auto &a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 998244353;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 2e+5 + 7;

ll ft[MAXN];
void update(int i, ll v) {
  for (; i <= MAXN; i += i & -i)
    ft[i] += v, ft[i] %= MOD;
}

ll get(int i) {
  ll ans = 0;
  for (; i > 0; i -= i & -i)
    ans += ft[i], ans %= MOD;
  return ans;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (auto &a : seg)
    cin >> a.first >> a.second;
  sort(seg.begin(), seg.end());
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = seg[j].f, r = seg[j].s;
      if (l > i)
        break;
      if (i >= l and i > r) {
        update(i, (get(i - l) - get(i - r - 1) + MOD) % MOD);
      } else if (i <= r and i >= l)
        update(i, (get(i - l) + MOD) % MOD);
    }
  }
  cout << (get(n) - get(n - 1) + MOD) % MOD << '\\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll tc = 1; // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wsign-compare"

#include <bits/stdc++.h>
using namespace std;

#define trav(a, A) for (auto &a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 998244353;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5 + 7;

ll ft[MAXN];
void update(int i, ll v) {
  for (; i <= MAXN; i += i & -i)
    ft[i] += v, ft[i] %= MOD;
}

ll get(int i) {
  ll ans = 0;
  for (; i > 0; i -= i & -i)
    ans += ft[i], ans %= MOD;
  return ans;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> seg(k);
  for (auto &a : seg)
    cin >> a.first >> a.second;
  sort(seg.begin(), seg.end());
  update(1, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      ll l = seg[j].f, r = seg[j].s;
      if (l > i)
        break;
      if (i >= l and i > r) {
        update(i, (get(i - l) - get(i - r - 1) + MOD) % MOD);
      } else if (i <= r and i > l)
        update(i, (get(i - l) + MOD) % MOD);
    }
  }
  cout << (get(n) - get(n - 1) + MOD) % MOD << '\\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll tc = 1; // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;

ll dp[maxn], l[maxn], r[maxn], sum[maxn];

void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i > l[j])
        dp[i] =
            (dp[i] + sum[i - l[j]] - sum[max(i - r[j] - 1, 0ll)] + mod) % mod;
    }
    sum[i] = (dp[i] + sum[i - 1]) % mod;
  }
  cout << dp[n] << '\\n';
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
  // freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

  // int t; cin >> t; while(t--)
  solve();

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define per(i, a, n) for (int i = (a); i > (n); i--)
typedef long long ll;
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;

ll dp[maxn], l[maxn], r[maxn], sum[maxn];

void solve() {
  ll n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = sum[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i] = (dp[i] + sum[i - l[j]] - sum[max(i - r[j] - 1, 0ll)]) % mod;
    }
    sum[i] = (dp[i] + sum[i - 1]) % mod;
  }
  cout << dp[n] << '\\n';
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
  // freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

  // int t; cin >> t; while(t--)
  solve();

  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x) - '0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

const int MAX = 2e5, mod = 998244353;
int n, k, a, b, dp[MAX], sum[MAX];
vii v;

int getSum(int a, int b) {
  if (b < 0)
    return 0;
  a = max(a, 0LL);
  if (a == 0)
    return sum[b];
  return (sum[b] - sum[a - 1]) % mod;
}

signed main() {
  fastio;
  cin >> n >> k;
  FOR(i, k) {
    cin >> a >> b;
    v.pb(mp(a, b));
  }
  dp[0] = sum[0] = 1;
  for (int i = 1; i < n; i++) {
    FOR(j, k) {
      dp[i] += getSum(i - v[j].se, i - v[j].fi);
      dp[i] %= mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << (dp[n - 1] % mod + mod) % mod;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);
#define all(x) x.begin(), x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for (int x = 0; x < n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x) - '0')
#define int ll
#define double long double
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};

const int MAX = 2e5, mod = 998244353;
int n, k, a, b, dp[MAX];
vi v;

int f(int x) {
  if (x > n)
    return 0;
  int &ret = dp[x];
  if (ret != -1)
    return ret;
  ret = 0;
  for (int i : v) {
    ret += f(x + i);
    ret %= mod;
  }
  return ret;
}

signed main() {
  fastio;
  ini(dp, -1);
  cin >> n >> k;
  FOR(i, k) {
    cin >> a >> b;
    for (int i = a; i <= b; i++)
      v.pb(i);
  }
  dp[n - 1] = 1;
  FOR(i, n) f(i);
  cout << f(0);
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL mod = 998244353;

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  vector<LL> dp(N + 1), num(K), sum(N + 1);
  dp[1] = 1, sum[1] = 1;
  for (int i = 2; i <= N; i++) {
    rep(j, K) {
      if (R[j] < i) {
        num[j] += dp[i - L[j]];
        num[j] -= dp[i - R[j] - 1];
        dp[i] += num[j];
      } else if (L[j] < i) {
        num[j] += dp[i - L[j]];
        dp[i] += sum[i - L[j]];
      }
      dp[i] %= mod;
      sum[i] = (sum[i - 1] + dp[i]);
      sum[i] %= mod;
    }
  }
  LL ans = dp[N];
  while (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL mod = 998244353;

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> L(K), R(K);
  rep(i, K) cin >> L[i] >> R[i];
  vector<LL> dp(N + 1), num(K);
  dp[1] = 1;
  for (int i = 2; i <= N; i++) {
    rep(j, K) {
      if (R[j] < i) {
        num[j] += dp[i - L[j]];
        num[j] -= dp[i - R[j] - 1];
        dp[i] += num[j];
      } else if (L[j] < i) {
        num[j] += dp[i - L[j]];
        for (int k = 1; k <= i - L[j]; k++)
          dp[i] += dp[k];
      }
      dp[i] %= mod;
    }
  }
  LL ans = dp[N];
  while (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main() {
  const int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1, 0), rui(n + 1), l(k), r(k);
  rep(i, k) { cin >> l[i] >> r[i]; }
  dp[1] = 1;
  rui[0] = 0;
  rui[1] = 1;
  for (int i = 2; i <= n; i++) {
    rep(j, k) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0)
        continue;
      li = max(li, 1);
      dp[i] += rui[ri] - rui[li - 1];
      dp[i] %= mod;
      dp[i] = (dp[i] + mod) % mod;
    }
    rui[i] = rui[i - 1] + dp[i];
    rui[i] %= mod;
  }
  cout << (dp[n] + mod) % mod << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> vec, dp(n, 0);
  rep(i, k) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      vec.push_back(j);
    }
  }
  dp[0] = 1;
  rep(i, n) {
    for (auto x : vec) {
      if (i - x >= 0) {
        dp[i] += dp[i - x];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 998244353
#define pi acos(-1.0)

ll f[200010], sum[200010], l[20], r[20];
int main() {
  ll t, n, i, j, k, lf, rt;
  sl2(n, k);
  for (int i = 0; i < k; i++) {
    sl2(l[i], r[i]);
  }
  sum[1] = f[1] = 1;
  for (int j = 2; j <= n; j++) {
    for (int i = 0; i < k; i++) {
      lf = max(1LL, j - r[i]);
      rt = j - l[i];
      if (rt < 1)
        continue;
      f[j] = ((f[j] + sum[rt] - sum[lf - 1]) % md + md) % md;
    }
    sum[j] = (sum[j - 1] + f[j]) % md;
  }
  cout << f[n]; //%md;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\\n"
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d%d", &a, &b)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld%lld", &a, &b)
#define pb push_back
#define mk make_pair
#define loop(n) for (int i = 0; i < n; i++)
#define FOR(a, b) for (int i = a; i <= b; i++)
#define sz size()
#define ff first
#define ss second
#define mem(a, val) memset(a, val, sizeof(a))
#define md 998244353
#define pi acos(-1.0)

ll p[100];
map<ll, ll> m;
map<vector<ll>, ll> mp;
vector<ll> v, vp, vv, vk;
ll ans = 0;
void solve(int s, ll n) {
  if (n < 0)
    return;
  if (n == 0) {
    vp = vv;

    sort(vp.begin(), vp.end());
    if (mp[vp] == 0) {
      int cnt = 0;
      if (vv.sz > 1)
        for (int i = 1; i < vv.sz; i++) {
          if (vv[i] == vv[i - 1])
            cnt++;
          else {
            if (cnt > 1)
              vk.pb(cnt);
            cnt = 0;
          }
        }
      if (vv[0] == vv[vv.size() - 1]) {
        ans++;
        ans %= md;
      } else {
        ans += p[vv.size()];
        ans %= md;
      }

      for (int i = 0; i < vk.sz; i++)
        ans %= vk[i];
      ans %= md;
      mp[vp] = 1;
    }
    return;
  }

  for (int i = s; i < v.size(); i++) {
    vv.pb(v[i]);
    solve(i, n - v[i]);
    vv.pop_back();
  }
}

int main() {
  ll a, b, t, n, i, j, k, l, mn = 0, mx = 0;

  p[0] = 1;
  for (int i = 1; i <= 22; i++)
    p[i] = p[i - 1] * i;

  sl2(n, k);
  for (int i = 0; i < k; i++) {
    cin >> a;
    if (m[a] == 0)
      v.pb(a), m[a] = 1;
    cin >> a;
    if (m[a] == 0)
      v.pb(a), m[a] = 1;
  }

  // for(int i=0; i<v.sz; i++)
  // cout<<v[i]<<" ";

  solve(0, n - 1);

  cout << ans;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int n, k;
veci s;
int dp[MAXN];
int p[MAXN];
bool was[MAXN];
pii ed[15];

void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i)
    cin >> ed[i].f >> ed[i].s;
  dp[1] = p[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      int r = max(0, i - ed[j].f), l = max(0, i - ed[j].s);
      dp[i] = (dp[i] + (p[r] - p[max(l - 1, 0)] + MOD2) % MOD2) % MOD2;
    }
    p[i] = (p[i - 1] + dp[i]) % MOD2;
  }
  cout << dp[n];
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
int n, k;
veci s;
int dp[MAXN];
bool was[MAXN];
int dfs(int v = 1) {
  if (~dp[v])
    return dp[v];
  int res = (v == n);
  for (auto to : s)
    if (v + to <= n) {
      res += dfs(v + to);
      if (res >= MOD2)
        res -= MOD2;
    }
  return dp[v] = res;
}

void solve() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    cin >> l >> r;
    while (l <= r)
      was[l++] = 1;
  }
  for (int i = 1; i <= n; ++i)
    if (was[i])
      s.pb(i);
  cout << dfs();
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\\n';
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define M 998244353
#define N 200001
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int t, n, k, a, b;
vector<pair<int, int>> off;
ll dp[N], suffDP[N + 1];
void printArray(int *, int);

ll sum(int idx, int l, int r) {
  if (r == n - 1)
    return suffDP[idx + l];

  return (suffDP[idx + l] - suffDP[idx + r + 1] + M) % M;
}

ll solve(int idx) {
  if (idx == n - 1)
    return 1;

  ll ans = 0;
  int f = 0;
  for (int i = 0; i < k && !f; i++) {
    if (off[i].s + idx < n)
      ans = (ans + sum(idx, off[i].f, off[i].s)) % M;
    else if (off[i].f + idx >= n)
      f = 1;
    else {
      ans = (ans + sum(idx, off[i].f, n - 1)) % M;
      f = 1;
    }
  }

  return ans;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    off.push_back({a, b});
  }

  sort(off.begin(), off.end());

  suffDP[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = solve(i);
    suffDP[i] = (dp[i] + suffDP[i + 1]) % M;
  }

  printf("%lld\\n", dp[0]);
  return 0;
}

void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++)
    printf("%d ", nums[i]);
  printf("\\n");
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define M 998244353
#define N 200001
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)

int t, n, k, a, b;
vector<int> off;
ll dp[N];
void printArray(int *, int);

ll solve(int idx) {
  if (idx == n - 1)
    return 1;

  if (dp[idx] != -1)
    return dp[idx];

  ll ans = 0;
  for (int i = 0; i < off.size(); i++) {
    if (idx + off[i] < n)
      ans = (ans + solve(idx + off[i])) % M;
    else
      break;
  }

  return dp[idx] = ans;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &a, &b);
    for (int j = a; j <= b; j++)
      off.push_back(j);
  }

  sort(off.begin(), off.end());

  for (int i = 0; i < n; i++)
    dp[i] = -1;
  printf("%lld\\n", solve(0));
  return 0;
}

void printArray(int *nums, int n) {
  for (int i = 0; i < n; i++)
    printf("%d ", nums[i]);
  printf("\\n");
}