Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline void out(T t) { cout << t << "\\n"; }
template <class T, class... Ts> inline void out(T t, Ts... ts) {
  cout << t << " ";
  out(ts...);
}
template <class T> inline bool CHMIN(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool CHMAX(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int INF = 1e18;

#define endl '\\n'
#define IOS()                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

signed main() {
  IOS();
  int N;
  string s;
  cin >> N >> s;
  vector<int> dp(N + 1);
  dp[0] = 1;
  FOR(i, 1, N + 1) { dp[i] += dp[i % __builtin_popcountll(i)] + 1; }
  vector<int> ans;
  int MOD = 0;
  REP(i, N) {
    if (s[i] == '1')
      ++MOD;
  }
  int plusMod = MOD + 1;
  int minusMod = MOD - 1;
  if (minusMod <= 0)
    minusMod = 1000000007;
  vector<int> plusPow(N);
  vector<int> minusPow(N);
  int plusNow = 1;
  int minusNow = 1;
  REP(i, N) {
    plusPow[N - 1 - i] = plusNow;
    minusPow[N - 1 - i] = minusNow;
    plusNow *= 2;
    plusNow %= plusMod;
    minusNow *= 2;
    minusNow %= minusMod;
  }
  int plus = 0, minus = 0;
  REP(i, N) {
    if (s[i] == '1') {
      plus += plusPow[i];
      minus += minusPow[i];
    }
  }
  REP(i, N) {
    if (s[i] == '1') {
      if (MOD == 1) {
        out(0);
        continue;
      }
      int t = minus;
      t -= minusPow[i];
      t = (t + minusMod) % minusMod;
      out(dp[t]);
    } else {
      int t = plus;
      t += plusPow[i];
      t = (t + plusMod) % plusMod;
      out(dp[t]);
    }
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline void out(T t) { cout << t << "\\n"; }
template <class T, class... Ts> inline void out(T t, Ts... ts) {
  cout << t << " ";
  out(ts...);
}
template <class T> inline bool CHMIN(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool CHMAX(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
constexpr int INF = 1e18;

#define endl '\\n'
#define IOS()                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

signed main() {
  IOS();
  int N;
  string s;
  cin >> N >> s;
  vector<int> dp(N + 1);
  dp[0] = 1;
  FOR(i, 1, N + 1) { dp[i] += dp[i % __builtin_popcountll(i)] + 1; }
  vector<int> ans;
  int MOD = 0;
  REP(i, N) {
    if (s[i] == '1')
      ++MOD;
  }
  int plusMod = MOD + 1;
  int minusMod = MOD - 1;
  vector<int> plusPow(N);
  vector<int> minusPow(N);
  int plusNow = 1;
  int minusNow = 1;
  REP(i, N) {
    plusPow[N - 1 - i] = plusNow;
    minusPow[N - 1 - i] = minusNow;
    plusNow *= 2;
    plusNow %= plusMod;
    minusNow *= 2;
    minusNow %= minusMod;
  }
  int plus = 0, minus = 0;
  REP(i, N) {
    if (s[i] == '1') {
      plus += plusPow[i];
      minus += minusPow[i];
    }
  }
  REP(i, N) {
    if (s[i] == '1') {
      int t = minus;
      t -= minusPow[i];
      t = (t + minusMod) % minusMod;
      out(dp[t]);
    } else {
      int t = plus;
      t += plusPow[i];
      t = (t + plusMod) % plusMod;
      out(dp[t]);
    }
  }
}