Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repi(i, a, b) for (int i = a; i < b; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define co(x) cout << x << "\n"
ll INF = 1000000007;
ll md = INF;

lint powmod_h;
lint powmod(lint a, int p) {
  if (!p)
    return 1;
  if (p % 2)
    return powmod(a, p - 1) * a % md;
  else {
    powmod_h = powmod(a, p / 2);
    return powmod_h * powmod_h % md;
  }
}
inline lint modmul(lint a, lint b) { return (a % md) * (b % md) % md; }
inline lint moddiv(lint a, lint b) { return modmul(a, powmod(b, md - 2)); }

lint fact[100010] = {}, revfact[100010] = {};
lint setFact(lint n) {
  fact[0] = 1;
  repi(i, 1, n) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= md;
  }
  revfact[n - 1] = powmod(fact[n - 1], md - 2);
  repr(i, n - 1) {
    revfact[i] = revfact[i + 1] * (i + 1);
    revfact[i] %= md;
  }
}
inline lint ncr(lint a, lint b) {
  return (((fact[a] * revfact[b]) % md) * revfact[a - b]) % md;
}

int main() {
  ll n;
  cin >> n;
  setFact(n + 2); // co(revfact[n]);co(ncr(31,1));co(endl);
  vector<ll> vec(n + 1);
  ll left, right;
  vector<ll> dp(n + 1, -1);
  for (int i = 0; i <= n; i++) {
    int k;
    cin >> k;
    if (dp[k] != -1) {
      left = dp[k];
      right = i;
      continue;
    }
    dp[k] = i;
  }

  for (int i = 1; i < n + 2; i++) {
    ll ans = 0;
    ans += ncr(n + 1, i);
    ans = (ans + INF - ncr(left + (n - right), i - 1)) % INF;
    cout << ans << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repi(i, a, b) for (int i = a; i < b; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define co(x) cout << x << "\n"
ll INF = 1000000007;
ll md = INF;

lint powmod_h;
lint powmod(lint a, int p) {
  if (!p)
    return 1;
  if (p % 2)
    return powmod(a, p - 1) * a % md;
  else {
    powmod_h = powmod(a, p / 2);
    return powmod_h * powmod_h % md;
  }
}
inline lint modmul(lint a, lint b) { return (a % md) * (b % md) % md; }
inline lint moddiv(lint a, lint b) { return modmul(a, powmod(b, md - 2)); }

lint fact[100010] = {}, revfact[100010] = {};
lint setFact(lint n) {
  fact[0] = 1;
  repi(i, 1, n) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= md;
  }
  revfact[n - 1] = powmod(fact[n - 1], md - 2);
  repr(i, n - 1) {
    revfact[i] = revfact[i + 1] * (i + 1);
    revfact[i] %= md;
  }
}
inline lint ncr(lint a, lint b) {
  if (a < b)
    return 0;
  return (((fact[a] * revfact[b]) % md) * revfact[a - b]) % md;
}

int main() {
  ll n;
  cin >> n;
  setFact(n + 2); // co(revfact[n]);co(ncr(31,1));co(endl);
  vector<ll> vec(n + 1);
  ll left, right;
  vector<ll> dp(n + 1, -1);
  for (int i = 0; i <= n; i++) {
    int k;
    cin >> k;
    if (dp[k] != -1) {
      left = dp[k];
      right = i;
      continue;
    }
    dp[k] = i;
  }

  for (int i = 1; i < n + 2; i++) {
    ll ans = 0;
    ans += ncr(n + 1, i);
    ans = (ans + INF - ncr(left + (n - right), i - 1)) % INF;
    cout << ans << endl;
  }
}