prithivMLmods/Coder-Stat huggingface dataset:
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int n, nn, q;
long long a[100001], ans[100001], num[100001];
stack<long long> s;
void solve(long long len, long long sum) {
  int pos = lower_bound(a + 1, a + nn + 1, len) - a - 1;
  if (!pos) {
    ans[1] += sum;
    ans[len + 1] -= sum;
    return;
  }
  num[pos] += len / a[pos] * sum;
  solve(len % a[pos], sum);
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  s.push(n);
  for (int i = 1; i <= q; i++) {
    long long x;
    scanf("%lld", &x);
    while (!s.empty() && x < s.top()) {
      s.pop();
    }
    s.push(x);
  }
  nn = s.size();
  for (int i = nn; i >= 1; i--) {
    a[i] = s.top();
    s.pop();
  }
  num[nn] = 1;
  for (int i = nn; i >= 1; i--) {
    solve(a[i], num[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += ans[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int n, nn, q;
long long a[200001], ans[200001], num[200001];
stack<long long> s;
void solve(long long len, long long sum) {
  int pos = lower_bound(a + 1, a + nn + 1, len) - a - 1;
  if (!pos) {
    ans[1] += sum;
    ans[len + 1] -= sum;
    return;
  }
  num[pos] += len / a[pos] * sum;
  solve(len % a[pos], sum);
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  s.push(n);
  for (int i = 1; i <= q; i++) {
    long long x;
    scanf("%lld", &x);
    while (!s.empty() && x < s.top()) {
      s.pop();
    }
    s.push(x);
  }
  nn = s.size();
  for (int i = nn; i >= 1; i--) {
    a[i] = s.top();
    s.pop();
  }
  num[nn] = 1;
  for (int i = nn; i >= 1; i--) {
    solve(a[i], num[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += ans[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;

const int N = 100010;

int n, q, t;
ll b[N], Q[N], a[N], c[N];

inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}

inline void read(int &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}

inline void read(ll &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}

inline void work(ll x, ll y) {
  int p = upper_bound(Q, Q + 1 + t, x) - Q - 1;
  if (!p)
    a[1] += y, a[x + 1] -= y;
  else
    c[p] += y * (x / Q[p]), work(x % Q[p], y);
}

int main() {
  read(n);
  read(q);
  if (q == 1) {
    for (int i = 1; i <= n; i++)
      printf("%d\n", 1);
    return 0;
  }
  for (int i = 1; i <= q; i++)
    read(b[i]);
  Q[++t] = b[q];
  for (int i = q - 1; i; i--) {
    if (b[i] >= Q[t])
      continue;
    Q[++t] = b[i];
  }
  if (n < Q[t])
    Q[++t] = n;
  reverse(Q + 1, Q + 1 + t);
  c[t] = 1;
  for (int i = t; i > 1; i--)
    c[i - 1] += c[i] * (Q[i] / Q[i - 1]), work(Q[i] % Q[i - 1], c[i]);
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1];
  for (int i = 1; i <= Q[1]; i++)
    a[i] += c[1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", a[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;

const int N = 100010;

int n, q, t;
ll b[N], Q[N], a[N], c[N];

inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}

inline void read(int &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}

inline void read(ll &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}

inline void work(ll x, ll y) {
  int p = upper_bound(Q, Q + 1 + t, x) - Q - 1;
  if (!p)
    a[1] += y, a[x + 1] -= y;
  else
    c[p] += y * (x / Q[p]), work(x % Q[p], y);
}

int main() {
  read(n);
  read(q);
  if (q == 0) {
    for (int i = 1; i <= n; i++)
      printf("%d\n", 1);
    return 0;
  }
  for (int i = 1; i <= q; i++)
    read(b[i]);
  Q[++t] = b[q];
  for (int i = q - 1; i; i--) {
    if (b[i] >= Q[t])
      continue;
    Q[++t] = b[i];
  }
  if (n < Q[t])
    Q[++t] = n;
  reverse(Q + 1, Q + 1 + t);
  c[t] = 1;
  for (int i = t; i > 1; i--)
    c[i - 1] += c[i] * (Q[i] / Q[i - 1]), work(Q[i] % Q[i - 1], c[i]);
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1];
  for (int i = 1; i <= Q[1]; i++)
    a[i] += c[1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", a[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1e18 + 1;

int N, Q;

ll q[100000], p[100001], c[100001], g[100001];
vector<ll> a;

int main() {

  cin >> N >> Q;
  ll M = INF;

  if (Q == 0) {
    for (int i = 0; i < N; i++)
      printf("%d\n", 1);
    return 0;
  }

  for (int i = 0; i < Q; i++)
    scanf("%lld", &q[i]);

  for (int i = Q - 1; i >= 0; i--) {
    if (q[i] < M) {
      a.push_back(q[i]);
      M = q[i];
    }
  }

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

  if (a[0] > N) {
    a.push_back(N);
    sort(a.begin(), a.end());
  }

  p[a.size() - 1]++;

  for (int i = a.size() - 1; i >= 0; i--) {

    ll R = a[i];

    while (R > a[0]) {
      int X = lower_bound(a.begin(), a.end(), R) - a.begin() - 1;
      p[X] += (R / a[X]) * p[i];
      R %= a[X];
    }

    c[R] += p[i];
  }

  ll S = 0;
  c[0] = 0;

  for (int i = 1; i <= a[0]; i++)
    S += c[i];

  for (int i = 1; i <= a[0]; i++) {
    S -= c[i - 1];
    g[i] = S;
  }

  for (int i = 1; i <= N; i++)
    printf("%lld\n", g[i]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1000000000000000001;

int N, Q;

ll q[100000], p[100001], c[100001], g[100001];
vector<ll> a;

int main() {

  cin >> N >> Q;
  ll M = INF;

  if (Q == 0) {
    for (int i = 0; i < N; i++)
      printf("%d\n", 1);
    return 0;
  }

  for (int i = 0; i < Q; i++)
    scanf("%lld", &q[i]);

  for (int i = Q - 1; i >= 0; i--) {
    if (q[i] < M) {
      a.push_back(q[i]);
      M = q[i];
    }
  }

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

  if (a[0] > N) {
    a.push_back(N);
    sort(a.begin(), a.end());
  }

  p[a.size() - 1]++;

  for (int i = a.size() - 1; i >= 0; i--) {

    ll R = a[i];

    while (R > a[0]) {
      int X = lower_bound(a.begin(), a.end(), R) - a.begin() - 1;
      p[X] += (R / a[X]) * p[i];
      R %= a[X];
    }

    c[R] += p[i];
  }

  ll S = 0;
  c[0] = 0;

  for (int i = 1; i <= a[0]; i++)
    S += c[i];

  for (int i = 1; i <= a[0]; i++) {
    S -= c[i - 1];
    g[i] = S;
  }

  for (int i = 1; i <= N; i++)
    printf("%lld\n", g[i]);

  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

typedef long long LL;
using namespace std;

const int MX = 100005;
int n, Q;
LL a[MX], dt[MX], t[MX], x, cur, c;

int main() {
  cin >> n >> Q, a[++c] = n;
  for (int i = 1; i <= Q; i++) {
    cin >> x;
    while (c && x <= a[c])
      --c;
    a[++c] = x;
  }
  t[c] = 1;
  for (int i = c; i; i--) {
    LL tmp = a[i], it = lower_bound(a + 1, a + i, tmp) - a;
    for (; it; it = lower_bound(a + 1, a + it, tmp) - a)
      t[it] += (tmp / a[it]) * t[i], tmp %= a[it];
    dt[1] += t[i], dt[tmp + 1] -= t[i];
  }
  for (int i = 1; i <= n; i++)
    cout << (cur += dt[i]) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

typedef long long LL;
using namespace std;

const int MX = 100005;
int n, Q;
LL a[MX], dt[MX], t[MX], x, cur, c;

int main() {
  cin >> n >> Q, a[++c] = n;
  for (int i = 1; i <= Q; i++) {
    cin >> x;
    while (c && x <= a[c])
      --c;
    a[++c] = x;
  }
  t[c] = 1;
  for (int i = c; i; i--) {
    LL tmp = a[i], it = upper_bound(a, a + i, tmp) - a - 1;
    for (; it; it = upper_bound(a, a + it, tmp) - a - 1)
      t[it] += (tmp / a[it]) * t[i], tmp %= a[it];
    dt[1] += t[i], dt[tmp + 1] -= t[i];
  }
  for (int i = 1; i <= n; i++)
    cout << (cur += dt[i]) << endl;
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int N, Q;
  scanf("%d %d", &N, &Q);
  vector<int> q(Q);
  REP(i, Q) scanf("%d", &q[i]);
  q.insert(q.begin(), N);
  Q++;

  llint whole = 1;
  map<llint, llint> prefs;
  prefs[0]++;

  for (int i = Q - 1; i > 0; --i) {
    prefs[q[i]] += whole;

    whole = 0;
    auto it = prefs.end();
    --it;
    vector<pair<llint, llint>> v;
    while (it->first >= q[i - 1] && it->first > 0) {
      v.push_back(*it);
      it--;
    }

    for (auto p : v) {
      whole += (p.first / q[i - 1]) * p.second;
      prefs[p.first % q[i - 1]] += p.second;
      prefs.erase(p.first);
    }
  }

  vector<llint> f(N + 1);
  f[N] += whole;
  for (auto &it : prefs) {
    f[it.first] += it.second;
  }

  vector<llint> ans(N + 1);
  llint cur = 0;
  for (llint i = N; i > 0; --i) {
    cur += f[i];
    ans[i] = cur;
  }

  FOR(i, 1, N + 1) printf("%lld\n", ans[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  int N, Q;
  scanf("%d %d", &N, &Q);
  vector<llint> q(Q);
  REP(i, Q) scanf("%lld", &q[i]);
  q.insert(q.begin(), N);
  Q++;

  llint whole = 1;
  map<llint, llint> prefs;
  prefs[0]++;

  for (int i = Q - 1; i > 0; --i) {
    prefs[q[i]] += whole;

    whole = 0;
    auto it = prefs.end();
    --it;
    vector<pair<llint, llint>> v;
    while (it->first >= q[i - 1] && it->first > 0) {
      v.push_back(*it);
      it--;
    }

    for (auto p : v) {
      whole += (p.first / q[i - 1]) * p.second;
      prefs[p.first % q[i - 1]] += p.second;
      prefs.erase(p.first);
    }
  }

  vector<llint> f(N + 1);
  f[N] += whole;
  for (auto &it : prefs) {
    f[it.first] += it.second;
  }

  vector<llint> ans(N + 1);
  llint cur = 0;
  for (llint i = N; i > 0; --i) {
    cur += f[i];
    ans[i] = cur;
  }

  FOR(i, 1, N + 1) printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  vector<ll> Q = {n};
  for (; q; q--) {
    int a;
    scanf("%d", &a);
    while (Q.size() && Q.back() >= a)
      Q.pop_back();
    Q.push_back(a);
  }
  map<ll, ll> M;
  M[Q.back()]++;
  for (int i = (int)Q.size() - 2; ~i; i--)
    while (M.rbegin()->first > Q[i]) {
      ll a = M.rbegin()->first, b = M.rbegin()->second;
      M[Q[i]] += a / Q[i] * b;
      M[a % Q[i]] += b;
      M.erase(a);
    }
  for (int i = n; i; i--)
    M[i] += M[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", M[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  vector<ll> Q = {n};
  for (; q; q--) {
    ll a;
    scanf("%lld", &a);
    while (Q.size() && Q.back() >= a)
      Q.pop_back();
    Q.push_back(a);
  }
  map<ll, ll> M;
  M[Q.back()]++;
  for (int i = (int)Q.size() - 2; ~i; i--)
    while (M.rbegin()->first > Q[i]) {
      ll a = M.rbegin()->first, b = M.rbegin()->second;
      M[Q[i]] += a / Q[i] * b;
      M[a % Q[i]] += b;
      M.erase(a);
    }
  for (int i = n; i; i--)
    M[i] += M[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", M[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, q, top;
ll sta[N], cnt[N];
map<ll, ll> M;
// M[x]表示长为x的序列有多少个
int main() {
  scanf("%d%d", &n, &q);
  while (q--) {
    ll x;
    scanf("%lld", &x);
    while (sta[top] >= x)
      top--;
    sta[++top] = x;
  }
  M[-sta[top]] = 1;
  for (int i = top - 1; i; i--) {
    ll T = sta[i];
    for (auto i : M) {
      ll v = -i.first, cnt = i.second;
      if (v <= T)
        break;
      M[-T] += cnt * (v / T);
      if (-v % T)
        M[-v % T] += cnt;
    }
    while (M.begin()->first < -T)
      M.erase(M.begin());
  }
  for (auto i : M)
    cnt[-i.first] += i.second;
  for (int i = n; i; i--)
    cnt[i] += cnt[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", cnt[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, q, top;
ll sta[N], cnt[N];
map<ll, ll> M;
// M[x]表示长为x的序列有多少个
int main() {
  scanf("%d%d", &n, &q);
  sta[top = 1] = n;
  while (q--) {
    ll x;
    scanf("%lld", &x);
    while (sta[top] >= x)
      top--;
    sta[++top] = x;
  }
  M[-sta[top]] = 1;
  for (int i = top - 1; i; i--) {
    ll T = sta[i];
    for (auto i : M) {
      ll v = -i.first, cnt = i.second;
      if (v <= T)
        break;
      M[-T] += cnt * (v / T);
      if (-v % T)
        M[-v % T] += cnt;
    }
    while (M.begin()->first < -T)
      M.erase(M.begin());
  }
  for (auto i : M)
    cnt[-i.first] += i.second;
  for (int i = n; i; i--)
    cnt[i] += cnt[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", cnt[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#define N (100000 + 1000)
using namespace std;

long long n, q, x, a[N], cnt, ans[N], f[N];

int main() {
  scanf("%lld%lld", &n, &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &x);
    while (cnt && x <= a[cnt])
      --cnt;
    a[++cnt] = x;
  }
  f[cnt] = 1;
  for (int i = cnt; i >= 1; --i) {
    long long k = a[i];
    while (k > a[1]) {
      long long t = lower_bound(a + 1, a + cnt + 1, k) - a - 1;
      f[t] += f[i] * (k / a[t]);
      k %= a[t];
    }
    ans[k] += f[i];
  }
  for (int i = n; i >= 1; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#define N (100000 + 1000)
using namespace std;

long long n, q, x, a[N], cnt, ans[N], f[N];

int main() {
  scanf("%lld%lld", &n, &q);
  a[++cnt] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &x);
    while (cnt && x <= a[cnt])
      --cnt;
    a[++cnt] = x;
  }
  f[cnt] = 1;
  for (int i = cnt; i >= 1; --i) {
    long long k = a[i];
    while (k > a[1]) {
      long long t = lower_bound(a + 1, a + cnt + 1, k) - a - 1;
      f[t] += f[i] * (k / a[t]);
      k %= a[t];
    }
    ans[k] += f[i];
  }
  for (int i = n; i >= 1; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 500005
#define int long long
using namespace std;
int n, m, top, b[N], f[N], ans[N];
signed main() {
  scanf("%lld%lld", &n, &m);
  b[++top] = n;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[++top]);
    while (top > 1 && b[top] <= b[top - 1])
      b[top - 1] = b[top], top--;
  }
  f[top] = 1;
  for (int i = top - 1; ~i; i--) {
    int len = b[i + 1];
    while (len > b[1]) {
      int pos = upper_bound(b + 1, b + i + 1, len) - b - 1;
      f[pos] += len / b[pos] * f[i + 1];
      len %= b[pos];
    }
    ans[len] += f[i + 1];
  }
  for (int i = b[1]; i; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 500005
#define int long long
using namespace std;
int n, m, top, b[N], f[N], ans[N];
signed main() {
  scanf("%lld%lld", &n, &m);
  b[++top] = n;
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &b[++top]);
    while (top > 1 && b[top] <= b[top - 1])
      b[top - 1] = b[top], top--;
  }
  f[top] = 1;
  for (int i = top - 1; ~i; i--) {
    int len = b[i + 1];
    while (len > b[1]) {
      int pos = upper_bound(b + 1, b + i + 1, len) - b - 1;
      f[pos] += len / b[pos] * f[i + 1];
      len %= b[pos];
    }
    ans[len] += f[i + 1];
  }
  for (int i = b[1]; i; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, q;
vector<llong> vt;
vector<pll> pv[100000];

int find(llong x) { return lower_bound(vt.begin(), vt.end(), x) - vt.begin(); }

void compress(vector<pll> &v) {
  sort(v.begin(), v.end());
  int i = 0;
  for (int j = 1; j < v.size(); ++j) {
    if (v[i].first == v[j].first)
      v[i].second += v[j].second;
    else
      v[++i] = v[j];
  }
  v.resize(i + 1);
}

llong sum[100001];
int main() {
  scanf("%d%d", &n, &q);
  llong x;
  vt.push_back(n);
  for (int i = 0; i < q; ++i) {
    scanf("%lld", &x);
    while (!vt.empty() && x <= vt.back())
      vt.pop_back();
    vt.push_back(x);
  }
  pv[vt.size() - 1].emplace_back(vt.back(), 1);
  for (int i = vt.size(); --i;) {
    if (pv[i].empty())
      continue;
    compress(pv[i]);
    for (pll j : pv[i]) {
      llong cnt = j.first / vt[i - 1];
      llong res = j.first - cnt * vt[i - 1];
      pv[i - 1].emplace_back(vt[i - 1], cnt * j.second);
      pv[find(res)].emplace_back(res, j.second);
    }
  }

  for (pll i : pv[0]) {
    sum[i.first] += i.second;
  }
  for (int i = n; --i;)
    sum[i] += sum[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", sum[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, q;
vector<llong> vt;
vector<pll> pv[100001];

int find(llong x) { return lower_bound(vt.begin(), vt.end(), x) - vt.begin(); }

void compress(vector<pll> &v) {
  sort(v.begin(), v.end());
  int i = 0;
  for (int j = 1; j < v.size(); ++j) {
    if (v[i].first == v[j].first)
      v[i].second += v[j].second;
    else
      v[++i] = v[j];
  }
  v.resize(i + 1);
}

llong sum[100001];
int main() {
  scanf("%d%d", &n, &q);
  llong x;
  vt.push_back(n);
  for (int i = 0; i < q; ++i) {
    scanf("%lld", &x);
    while (!vt.empty() && x <= vt.back())
      vt.pop_back();
    vt.push_back(x);
  }
  pv[vt.size() - 1].emplace_back(vt.back(), 1);
  for (int i = vt.size(); --i;) {
    if (pv[i].empty())
      continue;
    compress(pv[i]);
    for (pll j : pv[i]) {
      llong cnt = j.first / vt[i - 1];
      llong res = j.first - cnt * vt[i - 1];
      pv[i - 1].emplace_back(vt[i - 1], cnt * j.second);
      pv[find(res)].emplace_back(res, j.second);
    }
  }

  for (pll i : pv[0]) {
    sum[i.first] += i.second;
  }
  for (int i = n; --i;)
    sum[i] += sum[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", sum[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 111116

int n, q;
vector<long long> a;
long long t[N], ans[N];

long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -f;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}

int main() {
  n = read();
  q = read();
  a.push_back(n);
  for (int i = 1; i <= q; i++) {
    long long x = read();
    while (a.size() && a.back() >= x)
      a.pop_back();
    a.push_back(x);
  }
  q = a.size();
  t[q - 1] = 1;
  for (int i = q - 1; i >= 0; i--) {
    long long x = a[i], y = i - 1;
    while (y >= 0) {
      t[y] += x / a[y] * t[i];
      x %= a[y];
      for (int k = 1 << 16; k; k /= 2)
        if (y - k + 1 >= 0 && a[y - k + 1] > y)
          y -= k;
    }
    ans[1] += t[i];
    ans[x + 1] -= t[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i] += ans[i - 1]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 111116

int n, q;
vector<long long> a;
long long t[N], ans[N];

long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -f;
  for (; isdigit(ch); ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}

int main() {
  n = read();
  q = read();
  a.push_back(n);
  for (int i = 1; i <= q; i++) {
    long long x = read();
    while (a.size() && a.back() >= x)
      a.pop_back();
    a.push_back(x);
  }
  q = a.size();
  t[q - 1] = 1;
  for (int i = q - 1; i >= 0; i--) {
    long long x = a[i], y = i - 1;
    while (y >= 0) {
      t[y] += x / a[y] * t[i];
      x %= a[y];
      for (int k = 1 << 16; k; k /= 2)
        if (y - k + 1 >= 0 && a[y - k + 1] >= x)
          y -= k;
    }
    ans[1] += t[i];
    ans[x + 1] -= t[i];
  }
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i] += ans[i - 1]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> t3;

const int MX = 100005;
const int MM = 1000000007;

map<ll, ll> L;
vector<ll> X;
ll A[MX];

int main() {
  int N, Q, q;
  scanf("%d%d", &N, &Q);
  X.push_back(N);
  for (int i = 1; i <= Q; i++) {
    int a;
    scanf("%d", &a);
    while (X.size() && X.back() >= a)
      X.pop_back();
    X.push_back(a);
  }
  L[X.back()] = 1;

  while (X.size()) {
    ll p = L.rbegin()->first, q = L.rbegin()->second;
    while (X.size() && X.back() >= p)
      X.pop_back();
    if (X.empty())
      break;
    L.erase(--L.end());
    ll r = X.back();
    L[r] += q * (p / r);
    if (p % r)
      L[p % r] += q;
  }
  for (auto c : L) {
    A[0] += c.second;
    A[c.first + 1] -= c.second;
  }
  for (int i = 1; i <= N; i++)
    A[i] += A[i - 1];
  for (int i = 1; i <= N; i++)
    printf("%lld\n", A[i]);
}


Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> t3;

const int MX = 100005;
const int MM = 1000000007;

map<ll, ll> L;
vector<ll> X;
ll A[MX];

int main() {
  int N, Q, q;
  scanf("%d%d", &N, &Q);
  X.push_back(N);
  for (int i = 1; i <= Q; i++) {
    ll a;
    scanf("%lld", &a);
    while (X.size() && X.back() >= a)
      X.pop_back();
    X.push_back(a);
  }
  L[X.back()] = 1;

  while (X.size()) {
    ll p = L.rbegin()->first, q = L.rbegin()->second;
    while (X.size() && X.back() >= p)
      X.pop_back();
    if (X.empty())
      break;
    L.erase(--L.end());
    ll r = X.back();
    L[r] += q * (p / r);
    if (p % r)
      L[p % r] += q;
  }
  for (auto c : L) {
    A[0] += c.second;
    A[c.first + 1] -= c.second;
  }
  for (int i = 1; i <= N; i++)
    A[i] += A[i - 1];
  for (int i = 1; i <= N; i++)
    printf("%lld\n", A[i]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#define LL long long
const int maxn = 1e5 + 5;
using namespace std;
LL a[maxn], k[maxn], res[maxn];
int n, Q, cnt;
void work(int x, int v) {
  if (x <= a[1]) {
    res[1] += v;
    res[x + 1] -= v;
    return;
  }
  int t = upper_bound(a + 1, a + cnt + 1, x) - a;
  k[t - 1] += v * (x / a[t - 1]);
  work(x % a[t - 1], v);
}
int main() {
  scanf("%d%d", &n, &Q);
  a[cnt = 1] = n;
  for (int i = 1; i <= Q; i++) {
    LL x;
    scanf("%lld", &x);
    while (cnt > 0 && a[cnt] >= x)
      cnt--;
    a[++cnt] = x;
  }
  k[cnt] = 1;
  for (int i = cnt; i >= 2; i--) {
    k[i - 1] += k[i] * (a[i] / a[i - 1]);
    work(a[i] % a[i - 1], k[i]);
  }
  res[0] = k[1];
  res[a[1] + 1] -= k[1];
  for (int i = 1; i <= n; i++) {
    res[i] += res[i - 1];
    printf("%lld ", res[i]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#define LL long long
const int maxn = 1e5 + 5;
using namespace std;
LL a[maxn], k[maxn], res[maxn];
int n, Q, cnt;
void work(LL x, LL v) {
  if (x <= a[1]) {
    res[1] += v;
    res[x + 1] -= v;
    return;
  }
  int t = upper_bound(a + 1, a + cnt + 1, x) - a;
  k[t - 1] += v * (x / a[t - 1]);
  work(x % a[t - 1], v);
}
int main() {
  scanf("%d%d", &n, &Q);
  a[cnt = 1] = n;
  for (int i = 1; i <= Q; i++) {
    LL x;
    scanf("%lld", &x);
    while (cnt > 0 && a[cnt] >= x)
      cnt--;
    a[++cnt] = x;
  }
  k[cnt] = 1;
  for (int i = cnt; i >= 2; i--) {
    k[i - 1] += k[i] * (a[i] / a[i - 1]);
    work(a[i] % a[i - 1], k[i]);
  }
  res[0] = k[1];
  res[a[1] + 1] -= k[1];
  for (int i = 1; i <= n; i++) {
    res[i] += res[i - 1];
    printf("%lld ", res[i]);
  }
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

inline LL Read() {
  LL x = 0, f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}

const int MAXN = 100005;

map<LL, LL> s;
LL a[MAXN];
int n, m;

int main() {
#ifdef wxh010910
  freopen("data.in", "r", stdin);
#endif
  n = Read(), m = Read();
  for (int i = 1; i <= m; i++)
    a[i] = Read();
  LL cur = a[m];
  s[cur - 1] = 1;
  for (int i = m - 1; i; i--)
    if (a[i] < cur)
      for (cur = a[i]; (--s.end())->xx >= cur;) {
        auto it = --s.end();
        if (it->yy)
          s[cur - 1] += it->yy * (it->xx / cur), s[it->xx % cur] += it->yy;
        s.erase(it);
      }
  for (int i = n - 1; i; i--)
    s[i - 1] += s[i];
  for (int i = 0; i < n; i++)
    printf("%lld\n", s[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

inline LL Read() {
  LL x = 0, f = 1, c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + c - '0';
  return x * f;
}

const int MAXN = 100005;

map<LL, LL> s;
LL a[MAXN];
int n, m;

int main() {
#ifdef wxh010910
  freopen("data.in", "r", stdin);
#endif
  n = Read(), m = Read() + 1;
  a[1] = n;
  for (int i = 2; i <= m; i++)
    a[i] = Read();
  LL cur = a[m];
  s[cur - 1] = 1;
  for (int i = m - 1; i; i--)
    if (a[i] < cur)
      for (cur = a[i]; (--s.end())->xx >= cur;) {
        auto it = --s.end();
        if (it->yy)
          s[cur - 1] += it->yy * (it->xx / cur), s[it->xx % cur] += it->yy;
        s.erase(it);
      }
  for (int i = n - 1; i; i--)
    s[i - 1] += s[i];
  for (int i = 0; i < n; i++)
    printf("%lld\n", s[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
int n, q;
LL sta[N];
int top;
LL ti[N], ans[N];
map<LL, int, greater<LL>> mp;
map<LL, int, greater<LL>>::iterator itr;
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++) {
    LL t;
    scanf("%lld", &t);
    while (top > 0 && sta[top] >= t)
      top--;
    sta[++top] = t;
  }
  for (int i = 1; i <= top; i++)
    mp[sta[i]] = i;
  ti[top] = 1;
  for (int i = top; i >= 2; i--) {
    LL k = sta[i] % sta[i - 1], v;
    int id;
    ti[i - 1] += ti[i] * (sta[i] / sta[i - 1]);
    while ((itr = mp.lower_bound(k)) != mp.end()) {
      v = (*itr).first;
      id = (*itr).second;
      ti[id] += ti[i] * (k / v);
      k %= v;
    }
    ans[k] += ti[i];
  }
  ans[sta[1]] += ti[1];
  for (int i = n - 1; i >= 1; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;
int n, q;
LL sta[N];
int top;
LL ti[N], ans[N];
map<LL, int, greater<LL>> mp;
map<LL, int, greater<LL>>::iterator itr;
int main() {
  scanf("%d%d", &n, &q);
  sta[++top] = n;
  for (int i = 1; i <= q; i++) {
    LL t;
    scanf("%lld", &t);
    while (top > 0 && sta[top] >= t)
      top--;
    sta[++top] = t;
  }
  for (int i = 1; i <= top; i++)
    mp[sta[i]] = i;
  ti[top] = 1;
  for (int i = top; i >= 2; i--) {
    LL k = sta[i] % sta[i - 1], v;
    int id;
    ti[i - 1] += ti[i] * (sta[i] / sta[i - 1]);
    while ((itr = mp.lower_bound(k)) != mp.end()) {
      v = (*itr).first;
      id = (*itr).second;
      ti[id] += ti[i] * (k / v);
      k %= v;
    }
    ans[k] += ti[i];
  }
  ans[sta[1]] += ti[1];
  for (int i = n - 1; i >= 1; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long s64;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
const int N = 1e5 + 5;
s64 w[N], w0[N];
int q[N];

int main() {
  // freopen("1.in","r",stdin);
  int n, m;
  cin >> n >> m;
  int top = 0;
  q[0] = n;
  rep(i, 1, m) {
    s64 qi;
    scanf("%lld", &qi);
    while (top >= 0 && q[top] >= qi)
      --top;
    q[++top] = qi;
  }
  w[top] = 1;
  per(i, top, 0) {
    s64 l = q[i];
    int j = i;
    while (l > q[0]) {
      j = lower_bound(q, q + j, l) - q - 1;
      w[j] += l / q[j] * w[i];
      l %= q[j];
    }
    w0[l] += w[i];
  }
  per(i, q[0], 1) w0[i] += w0[i + 1];
  rep(i, 1, n) printf("%lld\n", w0[i]);
}

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

typedef long long s64;
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
const int N = 1e5 + 5;
s64 w[N], w0[N], q[N];

int main() {
  // freopen("1.in","r",stdin);
  int n, m;
  cin >> n >> m;
  int top = 0;
  q[0] = n;
  rep(i, 1, m) {
    s64 qi;
    scanf("%lld", &qi);
    while (top >= 0 && q[top] >= qi)
      --top;
    q[++top] = qi;
  }
  w[top] = 1;
  per(i, top, 0) {
    s64 l = q[i];
    int j = i;
    while (l > q[0]) {
      j = lower_bound(q, q + j, l) - q - 1;
      w[j] += l / q[j] * w[i];
      l %= q[j];
    }
    w0[l] += w[i];
  }
  per(i, q[0], 1) w0[i] += w0[i + 1];
  rep(i, 1, n) printf("%lld\n", w0[i]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int n, m;
  cin >> n >> m;
  vector<Int> a(m);
  for (Int i = 0; i < m; i++)
    cin >> a[i];
  a.emplace(a.begin(), n);
  stack<Int> b;
  for (Int i = 0; i < (Int)a.size(); i++) {
    while (!b.empty() && b.top() >= a[i])
      b.pop();
    if (b.empty() || b.top() < a[i])
      b.emplace(a[i]);
  }
  m = b.size();
  a.resize(m);
  for (Int i = 0; i < m; i++) {
    a[i] = b.top();
    b.pop();
  }

  vector<Int> t(m, 0), ans(n, 0);
  t[0] = 1;
  for (Int i = 0; i < m; i++) {
    Int k = a[i];
    Int j = i;
    while (1) {
      Int l = j, r = m;
      while (l + 1 < r) {
        Int p = (l + r) >> 1;
        if (k >= a[p])
          r = p;
        else
          l = p;
      }
      if (r == m)
        break;
      j = r;
      t[j] += t[i] * (k / a[j]);
      k %= a[j];
    }
    ans[0] += t[i];
    ans[k] -= t[i];
  }

  for (Int i = 1; i < n; i++)
    ans[i] += ans[i - 1];
  for (Int i = 0; i < n; i++)
    cout << ans[i] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
// INSERT ABOVE HERE
signed main() {
  Int n, m;
  cin >> n >> m;
  vector<Int> a(m);
  for (Int i = 0; i < m; i++)
    cin >> a[i];
  a.emplace(a.begin(), n);
  stack<Int> b;
  for (Int i = 0; i < (Int)a.size(); i++) {
    while (!b.empty() && b.top() >= a[i])
      b.pop();
    if (b.empty() || b.top() < a[i])
      b.emplace(a[i]);
  }
  m = b.size();
  a.resize(m);
  for (Int i = 0; i < m; i++) {
    a[i] = b.top();
    b.pop();
  }

  vector<Int> t(m, 0), ans(n + 1, 0);
  t[0] = 1;
  for (Int i = 0; i < m; i++) {
    Int k = a[i];
    Int j = i;
    while (1) {
      Int l = j, r = m;
      while (l + 1 < r) {
        Int p = (l + r) >> 1;
        if (k >= a[p])
          r = p;
        else
          l = p;
      }
      if (r == m)
        break;
      j = r;
      t[j] += t[i] * (k / a[j]);
      k %= a[j];
    }
    ans[0] += t[i];
    ans[k] -= t[i];
  }

  for (Int i = 1; i < n; i++)
    ans[i] += ans[i - 1];
  for (Int i = 0; i < n; i++)
    cout << ans[i] << endl;

  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <map>

const int N = 100001;

using LL = long long;

int m;
LL a[N];

int main() {
#ifdef LOCAL_JUDGE
  freopen("E.in", "r", stdin);
#endif
  scanf("%d%d", a, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d", a + i);
  }
  std::map<LL, LL> cnt;
  cnt[a[m]] = 1;
  for (int i = m - 1; i >= 0; --i) {
    auto it = cnt.upper_bound(a[i]);
    while (it != cnt.end()) {
      auto len = it->first;
      cnt[a[i]] += it->second * (len / a[i]);
      if (len % a[i]) {
        cnt[len % a[i]] += it->second;
      }
      auto backup = it;
      it++;
      cnt.erase(backup);
    }
  }
  LL res = 0;
  for (auto it : cnt) {
    res += it.second;
  }
  auto it = cnt.begin();
  for (int i = 1; i <= a[0]; ++i) {
    while (it != cnt.end() && it->first < i) {
      res -= it->second;
      it++;
    }
    printf("%lld\n", res);
  }
}


Fixed submission:
#include <cstdio>
#include <map>

const int N = 100001;

using LL = long long;

int m;
LL a[N];

int main() {
#ifdef LOCAL_JUDGE
  freopen("E.in", "r", stdin);
#endif
  scanf("%d%d", a, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%lld", a + i);
  }
  std::map<LL, LL> cnt;
  cnt[a[m]] = 1;
  for (int i = m - 1; i >= 0; --i) {
    auto it = cnt.upper_bound(a[i]);
    while (it != cnt.end()) {
      auto len = it->first;
      cnt[a[i]] += it->second * (len / a[i]);
      if (len % a[i]) {
        cnt[len % a[i]] += it->second;
      }
      auto backup = it;
      it++;
      cnt.erase(backup);
    }
  }
  LL res = 0;
  for (auto it : cnt) {
    res += it.second;
  }
  auto it = cnt.begin();
  for (int i = 1; i <= a[0]; ++i) {
    while (it != cnt.end() && it->first < i) {
      res -= it->second;
      it++;
    }
    printf("%lld\n", res);
  }
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e5 + 10;
#define ll long long
ll stk[N], f[N], ans[N];
int n, top, q;
void solve(ll x, ll v) {
  int k = upper_bound(stk + 1, stk + top + 1, x) - stk - 1;
  if (!k) {
    ans[1] += v;
    ans[x + 1] -= v;
    return;
  }
  f[k] += v * (x / stk[k]);
  solve(x % stk[k], v);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; i++) {
    ll x;
    scanf("%lld", &x);
    while (x <= stk[top] && top)
      --top;
    stk[++top] = x;
  }
  f[top] = 1;
  for (int i = top - 1; i; i--)
    f[i] += f[i + 1] * (stk[i + 1] / stk[i]),
        solve(stk[i + 1] % stk[i], f[i + 1]);
  ans[1] += f[1];
  ans[stk[1] + 1] -= f[1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i] += ans[i - 1]);
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e5 + 10;
#define ll long long
ll stk[N], f[N], ans[N];
int n, top, q;
void solve(ll x, ll v) {
  int k = upper_bound(stk + 1, stk + top + 1, x) - stk - 1;
  if (!k) {
    ans[1] += v;
    ans[x + 1] -= v;
    return;
  }
  f[k] += v * (x / stk[k]);
  solve(x % stk[k], v);
}
int main() {
  scanf("%d%d", &n, &q);
  stk[++top] = n;
  for (int i = 1; i <= q; i++) {
    ll x;
    scanf("%lld", &x);
    while (x <= stk[top] && top)
      --top;
    stk[++top] = x;
  }
  f[top] = 1;
  for (int i = top - 1; i; i--)
    f[i] += f[i + 1] * (stk[i + 1] / stk[i]),
        solve(stk[i + 1] % stk[i], f[i + 1]);
  ans[1] += f[1];
  ans[stk[1] + 1] -= f[1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i] += ans[i - 1]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
const int N = 1e5 + 7;
int n, m, tot;
long long a[N], f[N], c[N];
long long qread() {
  long long x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int main() {
  scanf("%d%d", &n, &m);
  long long x;
  for (int i = 1; i <= m; i++) {
    x = qread();
    while (tot && x <= a[tot])
      tot--;
    a[++tot] = x;
  }
  f[tot] = 1;
  for (int i = tot - 1; i; i--) {
    f[i] += a[i + 1] / a[i] * f[i + 1];
    long long tmp = a[i + 1] % a[i], t;
    while (tmp) {
      t = upper_bound(a + 1, a + tot + 1, tmp) - a - 1;
      if (t)
        f[t] += tmp / a[t] * f[i + 1], tmp %= a[t];
      else
        c[tmp] += f[i + 1], tmp = 0;
    }
  }
  c[a[1]] += f[1];
  for (int i = n - 1; i; i--)
    c[i] += c[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", c[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
using namespace std;
const int N = 1e5 + 7;
int n, m, tot;
long long a[N], f[N], c[N];
long long qread() {
  long long x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9')
    ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x;
}
int main() {
  scanf("%d%d", &n, &m);
  a[++tot] = n;
  long long x;
  for (int i = 1; i <= m; i++) {
    x = qread();
    while (tot && x <= a[tot])
      tot--;
    a[++tot] = x;
  }
  f[tot] = 1;
  for (int i = tot - 1; i; i--) {
    f[i] += a[i + 1] / a[i] * f[i + 1];
    long long tmp = a[i + 1] % a[i], t;
    while (tmp) {
      t = upper_bound(a + 1, a + tot + 1, tmp) - a - 1;
      if (t)
        f[t] += tmp / a[t] * f[i + 1], tmp %= a[t];
      else
        c[tmp] += f[i + 1], tmp = 0;
    }
  }
  c[a[1]] += f[1];
  for (int i = n - 1; i; i--)
    c[i] += c[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", c[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int n, q, t;
ll d[100010];
ll v[100010];
ll ans[100010];
int ef(ll x, int l, int r) {
  int mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (d[mid] > x)
      r = mid - 1;
    else
      l = mid;
  }
  return l;
}
int main() {
  scanf("%d%d", &n, &q);
  d[t = 2] = n;
  for (int i = 1; i <= q; i++) {
    ll x;
    scanf("%lld", &x);
    while (t > 0 && d[t] >= x)
      --t;
    d[++t] = x;
  }
  v[t] = 1;
  for (int i = t; i >= 3; i--) {
    ll x = d[i] - d[i - 1], y = x / d[i - 1];
    v[i - 1] += (d[i] / d[i - 1]) * v[i];
    x -= y * d[i - 1];
    int k = ef(x, 0, i);
    v[k] += v[i];
    x -= d[k];
    ans[x] += v[i];
  }
  ans[d[2]] += v[2];
  for (int i = d[2] - 1; i >= 1; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int n, q, t;
ll d[100010];
ll v[100010];
ll ans[100010];
int ef(ll x, int l, int r) {
  int mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (d[mid] > x)
      r = mid - 1;
    else
      l = mid;
  }
  return l;
}
int main() {
  scanf("%d%d", &n, &q);
  d[t = 2] = n;
  for (int i = 1; i <= q; i++) {
    ll x;
    scanf("%lld", &x);
    while (t > 0 && d[t] >= x)
      --t;
    d[++t] = x;
  }
  v[t] = 1;
  for (int i = t; i >= 3; i--) {
    int j = i - 1;
    ll zx = d[i];
    while (1) {
      ll x = zx - d[j], y = x / d[j];
      v[j] += (zx / d[j]) * v[i];
      zx = x - y * d[j];
      j = ef(zx, 1, j);
      if (zx <= d[2]) {
        ans[zx] += v[i];
        break;
      }
    }
  }
  ans[d[2]] += v[2];
  for (int i = d[2] - 1; i >= 1; i--)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; i++)
    printf("%lld\n", ans[i]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
#include <string.h>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9 + 7;

#define FO_OPEN 0
#define RG register
#define ST static

int n, q;
ll add[M], st[M], s[M], cur;
int stn = 0;

int main() {
  FO_OPEN ? freopen(".in", "r", stdin), freopen(".out", "w", stdout) : 0;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &cur);
    while (stn && st[stn] >= cur)
      --stn;
    st[++stn] = cur;
  }

  add[stn] = 1;
  for (int i = stn; i > 1; --i) {
    if (!add[i])
      continue;
    ll x = st[i];
    while (x >= st[1]) {
      int pos = upper_bound(st + 1, st + stn + 1, x) - st - 1;
      pos = min(pos, i - 1);
      add[pos] += add[i] * (x / st[pos]);
      x = x % st[pos];
    }
    s[x] += add[i];
    add[i] = 0;
  }

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


Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <string.h>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9 + 7;

#define FO_OPEN 0
#define RG register
#define ST static

int n, q;
ll add[M], st[M], s[M], cur;
int stn = 0;

int main() {
  FO_OPEN ? freopen(".in", "r", stdin), freopen(".out", "w", stdout) : 0;
  scanf("%d%d", &n, &q);
  st[++stn] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &cur);
    while (stn && st[stn] >= cur)
      --stn;
    st[++stn] = cur;
  }

  add[stn] = 1;
  for (int i = stn; i > 1; --i) {
    if (!add[i])
      continue;
    ll x = st[i];
    while (x >= st[1]) {
      int pos = upper_bound(st + 1, st + stn + 1, x) - st - 1;
      pos = min(pos, i - 1);
      add[pos] += add[i] * (x / st[pos]);
      x = x % st[pos];
    }
    s[x] += add[i];
    add[i] = 0;
  }

  s[st[1]] += add[1];
  for (int i = n; i; --i)
    s[i] += s[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", s[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;
int arr[maxn];
ii qr[maxn];
int a[maxn];
int t[maxn];
int ans[maxn];
signed main() {
  freopen("lon.inp", "r", stdin);
  freopen("lon.out", "w", stdout);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    cin >> qr[i].fi;
    qr[i].se = i;
  }
  qr[0] = ii(n, 0);
  sort(qr, qr + 1 + q);
  int sz = 0;
  int cur = -1;
  for (int i = 0; i <= q; i++) {
    if (qr[i].se > cur) {
      cur = qr[i].se;
      arr[++sz] = qr[i].fi;
      // cout<<"arr "<<sz<<" "<<qr[i].fi<<endl;
    }
  }
  t[sz] = 1;
  // cout<<"sz = "<<sz<<endl;
  // cout<<"mark = "<<arr[1]<<endl;
  for (int i = sz; i > 1; i--) {
    int k = arr[i] % arr[i - 1];
    // cout<<"k = "<<k<<endl;
    while (k > arr[1]) {
      int pos = upper_bound(arr + 1, arr + sz + 1, k) - arr - 1;
      // cout<<"pos = "<<pos<<endl;
      t[pos] += t[i] * (k / arr[pos]);
      k %= arr[pos];
      // cout<<"t[pos] = "<<t[pos]<<endl;
    }
    // cout<<"k = "<<k<<endl;
    // cout<<"a[k] += "<<t[i]<<endl;
    a[k] += t[i];
    t[i - 1] += t[i] * (arr[i] / arr[i - 1]);
    // cout<<"i = "<<i<<endl;
  }
  a[arr[1]] += t[1];
  for (int i = arr[1]; i >= 1; i--) {
    a[i] += a[i + 1];
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;
int arr[maxn];
ii qr[maxn];
int a[maxn];
int t[maxn];
int ans[maxn];
signed main() {
  // freopen("lon.inp","r",stdin);
  // freopen("lon.out","w",stdout);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= q; i++) {
    cin >> qr[i].fi;
    qr[i].se = i;
  }
  qr[0] = ii(n, 0);
  sort(qr, qr + 1 + q);
  int sz = 0;
  int cur = -1;
  for (int i = 0; i <= q; i++) {
    if (qr[i].se > cur) {
      cur = qr[i].se;
      arr[++sz] = qr[i].fi;
      // cout<<"arr "<<sz<<" "<<qr[i].fi<<endl;
    }
  }
  t[sz] = 1;
  // cout<<"sz = "<<sz<<endl;
  // cout<<"mark = "<<arr[1]<<endl;
  for (int i = sz; i > 1; i--) {
    int k = arr[i] % arr[i - 1];
    // cout<<"k = "<<k<<endl;
    while (k > arr[1]) {
      int pos = upper_bound(arr + 1, arr + sz + 1, k) - arr - 1;
      // cout<<"pos = "<<pos<<endl;
      t[pos] += t[i] * (k / arr[pos]);
      k %= arr[pos];
      // cout<<"t[pos] = "<<t[pos]<<endl;
    }
    // cout<<"k = "<<k<<endl;
    // cout<<"a[k] += "<<t[i]<<endl;
    a[k] += t[i];
    t[i - 1] += t[i] * (arr[i] / arr[i - 1]);
    // cout<<"i = "<<i<<endl;
  }
  a[arr[1]] += t[1];
  for (int i = arr[1]; i >= 1; i--) {
    a[i] += a[i + 1];
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << "\n";
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int tp = 0;
long long dp[100005], sta[100005], pre[100005];
inline void dac(long long len, long long val) {
  int pos = upper_bound(sta + 1, sta + tp + 1, val) - sta - 1;
  if (!pos)
    return pre[1] += val, pre[len + 1] -= val, void();
  dp[pos] += val * (len / sta[pos]);
  return dac(len % sta[pos], val);
}
int main() {
  int n, q;
  long long x;
  scanf("%d%d", &n, &q), sta[tp = 1] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &x);
    while (tp && sta[tp] >= x)
      --tp;
    sta[++tp] = x;
  }
  dp[tp] = 1;
  for (int i = tp - 1; i; --i) {
    dp[i] += dp[i + 1] * (sta[i + 1] / sta[i]),
        dac(sta[i + 1] % sta[i], dp[i + 1]);
  }
  pre[1] += dp[1], pre[sta[1] + 1] -= dp[1];
  for (int i = 1; i <= n; ++i)
    pre[i] += pre[i - 1], printf("%lld\n", pre[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int tp = 0;
long long dp[100005], sta[100005], pre[100005];
inline void dac(long long len, long long val) {
  int pos = upper_bound(sta + 1, sta + tp + 1, len) - sta - 1;
  if (!pos)
    return pre[1] += val, pre[len + 1] -= val, void();
  dp[pos] += val * (len / sta[pos]);
  return dac(len % sta[pos], val);
}
int main() {
  int n, q;
  long long x;
  scanf("%d%d", &n, &q), sta[tp = 1] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &x);
    while (tp && sta[tp] >= x)
      --tp;
    sta[++tp] = x;
  }
  dp[tp] = 1;
  for (int i = tp - 1; i; --i) {
    dp[i] += dp[i + 1] * (sta[i + 1] / sta[i]),
        dac(sta[i + 1] % sta[i], dp[i + 1]);
  }
  pre[1] += dp[1], pre[sta[1] + 1] -= dp[1];
  for (int i = 1; i <= n; ++i)
    pre[i] += pre[i - 1], printf("%lld\n", pre[i]);
  return 0;
}