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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

template <typename T> vector<T> smallest_prime_factors(T n) {
  // 1-indexedにできるようにする
  vector<T> spf(n + 1);
  // 最初は全て素数と仮定する．このとき最小の素因数はその数自身になるはず
  for (T i = 0; i <= n; i++)
    spf[i] = i;

  // ある素数の一定倍したものは必ず最小の素因数として元の素数を持つはず
  // これに従い，小さいほうから順に更新をかけていく
  for (T i = 2; i * i <= n; i++) {
    // iが素数の場合
    if (spf[i] == i) {
      // i以上の数でiを素因数に含むものを探し，最小の素因数を更新する
      // i*iより小さいものは必ずiよりも小さい素数ですでに更新されているはず
      for (T j = i * i; j <= n; j += i) {
        // まだ更新されていないものだけ更新する
        if (spf[j] == j)
          spf[j] = i;
      }
    }
  }
  return spf;
}

// 素因数分解
template <typename T> vector<T> factolization(T x, vector<T> &spf) {
  vector<T> ret;
  // 本来は2から順に割り切れるか試すが，すでに最小の素因数を得ているので，試す必要はない
  while (x != 1) {
    ret.push_back(spf[x]);
    x /= spf[x];
  }
  return ret;
}

ll num_div(ll n, vector<ll> &spf) {
  auto tmp = factolization(n, spf);
  map<ll, ll> mp;
  for (auto &&e : tmp) {
    mp[e]++;
  }
  ll ans = 1;
  for (auto &&e : mp) {
    ans *= (e.second + 1);
  }
  return ans;
}

int main() {
  auto spf = smallest_prime_factors(1000050LL);
  ll n, ans = 0;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    ans += num_div(n - i, spf);
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

ll num_div(ll n) {
  ll cnt = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0)
      cnt += 2;
    if (n == i * i)
      cnt--;
  }
  return cnt;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll c = 1; c < n; ++c) {
    ans += num_div(n - c);
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int c = 1; c < N; c++) {
    int tmp = N - c;
    float x = sqrt(tmp);

    for (int b = 1; b < x; b++) {
      if (tmp % b == 0)
        ans += 2;
    }

    if (floor(x) == x) {
      if (tmp % (int)x == 0)
        ans += 1;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int c = 1; c < N; c++) {
    int tmp = N - c;
    for (int b = 1; b <= sqrt(tmp); b++) {
      if (tmp % b == 0) {
        if (b == sqrt(tmp)) {
          ans += 1;
        } else {
          ans += 2;
        }
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

// AtCoder Beginner Contest 179 C.cpp

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

using namespace std;

int main() {
  int n;
  cin >> n;

  int an = 0;
  for (int i = 1; i < n; i++) {
    an += (n - 1) / i;
  }

  cout << an << endl;
}


Error: TLE

Fixed submission:

// AtCoder Beginner Contest 179 C.cpp

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

using namespace std;

template <int size> struct arr {
  int sto[size];
  constexpr arr() {
    for (int64_t n = size - 1; n != 0; n--) {
      int64_t i, co;
      bool f = false;
      for (i = 1, co = 0; i * i <= n; i++) {
        if (i * i == n) {
          f = true;
        } else {
          if (n % i == 0) {
            co++;
          }
        }
      }
      sto[n] = (f ? co * 2 + 1 : co * 2);
    }
  }
};
arr<1000000> a;
int main() {
  int64_t n, an = 0;
  cin >> n;

  for (int i = 1; i < n; i++) {
    an += a.sto[i];
  }
  cout << an << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; i * j < n; j++) {

      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (i * j < n)
        cnt++;
    }
  }
  cout << cnt;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n - 1; ++i) {
    for (int j = 1; j * i <= n - 1; ++j) {
      ans++;
    }
  }
  cout << ans << endl;
}

int32_t main() {
  IOS ll T = 1;
  // cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define N 1000005

using namespace std;

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n - 1; ++i) {
    ll x = sqrt(n - i);
    for (int j = 1; j <= x; ++j) {
      if ((n - i) % j == 0) {
        if (j == (n - i) / j)
          ans++;
        else
          ans += 2;
      }
    }
  }
  cout << ans << endl;
}

int32_t main() {
  IOS ll T = 1;
  // cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i < N; i++) {
    ans += (N - 1) / i;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N - 1; i++) {
    for (ll j = 1; j <= sqrt(N - i); j++) {
      if ((N - i) % j == 0 && (N - i) / j != j)
        ans += 2;
      else if ((N - i) % j == 0 && (N - i) / j == j)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  int cou = 0;
  cin >> n;

  for (int a = 1; a < n; a++) {
    for (int b = 1; b < n; b++) {
      if (a * b < n) {
        cou++;
      } else {
        break;
      }
    }
  }
  cout << cou << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  int cou = 0;
  cin >> n;

  for (int a = 1; a < n; a++) {
    for (int b = 1; b < n; b++) {
      for (int c = 1; c < n; c++) {
        if (a * b + c == n) {
          cou++;
        }
      }
    }
  }
  cout << cou << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n / i; j++) {
      if (i * j < n) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i * j < n) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple<int, int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pci pair<char, int>
#define psi pair<string, int>
#define pis pair<int, string>

#define vi vector<int>
#define vd vector<double>
#define vld vector<ld>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vpi vector<pii>
#define vpll vector<pll>
#define vpis vector<pis>

#define pb push_back
#define mt make_tuple
#define gt0 get<0>
#define gt1 get<1>
#define gt2 get<2>

#define pi acos(-1)

#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

using namespace std;

const int maxn = 1e6 + 5;
const int mod = 1e9 + 9;

int a[maxn];

void solve() {
  fill(a, a + maxn, 2);
  a[1] = 1;

  for (int i = 2; i < maxn; i++) {
    for (int j = i + i; j < maxn; j += i)
      a[j]++;
  }
}

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fast;

  solve();

  int n;

  scanf("%d", &n);

  ll ans = 0;

  for (int i = 1; i < n; i++) {
    int tmp = n - i;
    ans += a[tmp];
  }

  printf("%lld\\n", ans);

  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define ll long long
#define ull unsigned long long
#define ld long double

#define tiii tuple<int, int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pci pair<char, int>
#define psi pair<string, int>
#define pis pair<int, string>

#define vi vector<int>
#define vd vector<double>
#define vld vector<ld>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vpi vector<pii>
#define vpll vector<pll>
#define vpis vector<pis>

#define pb push_back
#define mt make_tuple
#define gt0 get<0>
#define gt1 get<1>
#define gt2 get<2>

#define pi acos(-1)

#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)

using namespace std;

const int maxn = 1e5 + 5;
const int mod = 1e9 + 9;

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  fast;

  int n;

  scanf("%d", &n);

  ll ans = 0;

  for (int i = 1; i < n; i++) {
    int tmp = n - i;
    ll sum = 0;

    for (int j = 1; j * j <= tmp; j++) {
      if (tmp % j == 0) {
        if ((tmp / j) == j)
          sum++;
        else
          sum += 2;
      }
    }

    ans += sum;
  }

  printf("%lld\\n", ans);

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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main() {
  unsigned int N;
  unsigned int count = 0;
  unsigned int sq_count = 0;
  cin >> N;

  for (int a = 1; a < N; a++) {
    count += (N - 1) / a;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  unsigned int N;
  unsigned int count = 0;
  unsigned int sq_count = 0;
  cin >> N;
  for (unsigned int i = 1; i < N; i++) {
    unsigned int n = N - i;
    for (unsigned int j = 1; j <= n; j++) {
      if (n % j == 0) {
        count++;
      }
    }
  }
  // count=(count-sq_count)*2+sq_count;
  cout << count << endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  std::cin >> n;
  int count = 0;
  for (int a = 1; a < n; a++) {
    for (int b = 1; b <= (n - 1) / a; b++) {
      count += 1;
    }
  }
  std::cout << count << std::endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  std::cin >> n;

  bool over = false;
  int count = 0;
  for (int c = 1; c < n; c++) {
    // std::cout << c << std::endl;
    for (int a = 1; a < n; a++) {
      for (int b = a; b < n; b++) {
        // std::cout << a << ":" << b << std::endl;
        if (a * b > n - c) {
          break;
        }
        if (a * b == n - c) {
          if (a == b) {
            count++;
          } else {
            count += 2;
          }
        }
      }
    }
  }
  std::cout << count << std::endl;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int a, b, c, cnt; // 制御変数
  int n;
  scanf("%d", &n);
  cnt = 0;

  for (a = 1; a < n; a++) {
    for (b = 1; b < n; b++) {
      if (a * b >= n)
        break;
      // cの期待値を求める
      c = n - a * b;
      if (c > 0) { // cは0以上
        cnt++;
      }
    }
  }
  printf("%d", cnt);
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int a, b, c, cnt; // 制御変数
  int n;
  scanf("%d", &n);
  cnt = 0;

  for (a = 1; a < n; a++) {
    for (b = 1; b < n; b++) {
      if (a * b >= n)
        continue;
      // cの期待値を求める
      c = n - a * b;
      if (c > 0) { // cは0以上
        cnt++;
      }
    }
  }
  printf("%d", cnt);
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<pairs, null_type, greater<pairs>, rb_tree_tag,                          \\
       tree_order_statistics_node_update>
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD = (1e9 + 7);
typedef pair<ll, ll> pairs;
ll power(ll a, ll b) {
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll fact(ll n) {
  ll i, cnt = 0, temp, ans = 1;
  ;
  while (n % 2 == 0) {
    n /= 2;
    cnt++;
  }
  temp = n;
  ans *= cnt + 1;
  for (i = 3; i * i <= temp; i += 2) {
    cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    ans *= cnt + 1;
  }
  if (n > 2)
    ans *= 2;
  return ans;
}
int main() {
  // your code goes here
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t, n, i, j, k, c, f, ans = 0;
  cin >> n;
  vc num(n + 1);
  for (i = 1; i < n; i++) {
    for (j = i; j < n; j += i)
      num[j]++;
  }
  for (i = 1; i < n; i++) {
    ans += num[n - i];
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<pairs, null_type, greater<pairs>, rb_tree_tag,                          \\
       tree_order_statistics_node_update>
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD = (1e9 + 7);
typedef pair<ll, ll> pairs;
ll power(ll a, ll b) {
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll fact(ll n) {
  ll i, cnt = 0, temp, ans = 1;
  ;
  while (n % 2 == 0) {
    n /= 2;
    cnt++;
  }
  temp = n;
  ans *= cnt + 1;
  for (i = 3; i * i <= temp; i += 2) {
    cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    ans *= cnt + 1;
  }
  if (n > 2)
    ans *= 2;
  return ans;
}
int main() {
  // your code goes here
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t, n, i, j, k, c, f, ans = 0;
  cin >> n;
  for (i = 1; i < n; i++) {
    ans += fact(n - i);
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int cou = 0;
  int n;
  cin >> n;
  int a = 1;
  int b = 1;
  while (1) {
    if (a > n) {
      break;
    }
    int b = 1;
    while (1) {
      if (n > a * b) {
        cou++;
      } else if (n <= a * b) {
        break;
      }
      b++;
    }
    a++;
  }

  cout << cou << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int g = 0;
  int n;
  cin >> n;
  for (int64_t a = 1; a < 1000000; a++) {
    for (int64_t b = 1; b < 1000000; b++) {
      for (int64_t c = 1; c < 1000000; c++) {
        if (a * b + c == n) {
          g++;
        }
      }
    }
  }
  cout << g << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;

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

  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> s;
  vector<int> dp(2 * n + 5);

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    s.push_back({l, r});
  }

  /*
  for(int j:s){
          cout<<j<<' ';
  }
  cout<<'\\n';
  */
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i - 1] + dp[i]) % mod;
    for (int j = 0; j < k; j++) {
      int l = s[j].first, r = s[j].second;

      dp[i + l] = (dp[i] + dp[i + l]) % mod;
      dp[i + r + 1] = (dp[i + r + 1] - dp[i]) % mod;
    }
  }
  ll ans = (dp[n] - dp[n - 1] + mod) % mod;
  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;

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

  int n, k;
  cin >> n >> k;
  vector<int> s, dp(n + 1);

  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    while (l <= r) {
      s.push_back(l);
      l++;
    }
  }

  /*
  for(int j:s){
          cout<<j<<' ';
  }
  cout<<'\\n';
  */
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j : s) {
      if (i + j <= n) {
        dp[i + j] = (dp[i + j] + dp[i]) % mod;
      }
    }
  }
  cout << dp[n] << '\\n';
  return 0;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long int
#define ull unsigned long long int
#define forr(i, n) for (int i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\\n'
#define ce(ele) cout << ele << ' '
#define cs(ele) cout << ele << '\\n'
#define CASE(t)                                                                \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define vi vector<ll>
const ll md = 1e9 + 7;
const ll M1 = 998244353;
ll mod(ll n) { return ((n % M1) + M1) % M1; }
ll power(ll x, ll y) {
  ll res = 1;
  x = x;
  while (y > 0) {
    if (y & 1)
      res = res * x;
    x = x * x;
    y = y >> 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  f(i, 0, k) cin >> v[i].F >> v[i].S;

  vi dp(n + 1, 0);
  dp[0] = 0, dp[1] = 1;
  f(i, 2, n + 1) {
    ll cur = 0;
    f(j, 0, k) {
      if (v[j].F >= i)
        continue;
      ll l = max(1LL, i - v[j].S);
      ll r = i - v[j].F;
      cur += dp[r] - dp[l - 1];
    }
    cur = mod(cur);
    dp[i] = mod(dp[i - 1] + cur);
  }
  cs(mod(dp[n] - dp[n - 1]));
  // f(i,1,n+1)cs(dp[i]);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

int main() {
  fast();
  ll n, k, d1, d2, m = 998244353;
  cin >> n >> k;
  set<ll> s;
  for (int i = 0; i < k; i++) {
    cin >> d1 >> d2;
    for (int j = d1; j <= d2; j++) {
      s.insert(j);
    }
  }
  ll dp[n + 1];
  memset(dp, 0, sizeof dp);
  dp[1] = 1;
  set<ll>::iterator it;
  for (ll i = 1; i < n; i++) {
    for (it = s.begin(); it != s.end(); it++) {
      if (*it + i <= n) {
        dp[*it + i] = dp[*it + i] + dp[i];
        dp[*it + i] = dp[i + *it] % m;
      } else {
        break;
      }
    }
  }
  cout << dp[n];

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

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

const int MOD = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  REP(i, K) { cin >> L[i] >> R[i]; }
  vector<ll> dp(N + 1, 0);
  dp[0] = 1;

  REP(i, N - 1) {
    if (i != 0)
      dp[i] += dp[i - 1];
    dp[i] = (dp[i] + MOD) % MOD;
    REP(k, K) {
      if (i + L[k] <= N - 1) {
        dp[i + L[k]] += dp[i];
        dp[i + L[k]] = (dp[i + L[k]] + MOD) % MOD;
      }
      if (i + R[k] + 1 <= N - 1) {
        dp[i + R[k] + 1] -= dp[i];
        dp[i + R[k] + 1] = (dp[i + R[k] + 1] + MOD) % MOD;
      }
    }
    // REP(i,N){
    //     cout << dp[i] << " ";
    // }
    // cout << endl;
  }
  cout << (dp[N - 1] + MOD) % MOD << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

const int MOD = 998244353;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  REP(i, K) { cin >> L[i] >> R[i]; }
  vector<ll> dp(N + 1, 0);
  dp[0] = 1;

  REP(i, N - 1) {
    if (i != 0)
      dp[i] += dp[i - 1];
    dp[i] = (dp[i] + MOD) % MOD;
    REP(k, K) {
      if (i + L[k] <= N - 1) {
        dp[i + L[k]] += dp[i];
        dp[i + L[k]] = (dp[i + L[k]] + MOD) % MOD;
      }
      if (i + R[k] + 1 <= N - 1)
        dp[i + R[k] + 1] -= dp[i];
      dp[i + R[k] + 1] = (dp[i + R[k] + 1] + MOD) % MOD;
    }
    // REP(i,N){
    //     cout << dp[i] << " ";
    // }
    // cout << endl;
  }
  cout << (dp[N - 1] + MOD) % MOD << endl;
  return 0;
}