Problem p03083 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define Rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define Repe(i, a, b) for (register int i = (a); i >= (b); --i)
#define rep(i, a, b) for (register int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define mx(a, b) (a > b ? a : b)
#define mn(a, b) (a < b ? a : b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO {
const uint32 Buffsize = 1 << 15, Output = 1 << 24;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
  return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
              ? 0
              : *S++);
}
static char Out[Output], *nowps = Out;

inline void flush() {
  fwrite(Out, 1, nowps - Out, stdout);
  nowps = Out;
}

template <typename T> inline void read(T &x) {
  x = 0;
  static char ch;
  T f = 1;
  for (ch = getc(); !isdigit(ch); ch = getc())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getc())
    x = x * 10 + (ch ^ 48);
  x *= f;
}

template <typename T> inline void write(T x, char ch = '\n') {
  if (!x)
    *nowps++ = '0';
  if (x < 0)
    *nowps++ = '-', x = -x;
  static uint32 sta[111], tp;
  for (tp = 0; x; x /= 10)
    sta[++tp] = x % 10;
  for (; tp; *nowps++ = sta[tp--] ^ 48)
    ;
  *nowps++ = ch;
  if (nowps - Out >= 1 << 23)
    flush();
}
} // namespace IO
using namespace IO;

void file() {
#ifndef ONLINE_JUDGE
  FILE *DSD = freopen("water.in", "r", stdin);
  FILE *CSC = freopen("water.out", "w", stdout);
#endif
}

inline void Chkmin(int &u, int v) { u > v ? u = v : 0; }

inline void Chkmax(int &u, int v) { u < v ? u = v : 0; }

inline void Chkmax(ll &u, ll v) { u < v ? u = v : 0; }

inline void Chkmin(ll &u, ll v) { u > v ? u = v : 0; }

const int MAXN = 2e5 + 7, mod = 1e9 + 7;

static int fac[MAXN], inv[MAXN];

inline int power(int u, int v) {
  register int sm;
  for (sm = 1; v; v >>= 1, u = (ll)u * u % mod)
    if (v & 1)
      sm = (ll)sm * u % mod;
  return sm;
}

static int B, W;

inline void init() { read(B), read(W); }

inline int C(int u, int v) {
  return u < v ? 0 : (ll)fac[u] * inv[v] % mod * inv[u - v] % mod;
}

static int prb, prw;

inline int ad(int u, int v) { return (u += v) >= mod ? u - mod : u; }

inline void solve() {
  fac[0] = 1;
  Rep(i, 1, W + B) fac[i] = (ll)fac[i - 1] * i % mod;
  inv[W + B] = power(fac[W + B], mod - 2);
  Repe(i, W + B, 1) inv[i - 1] = (ll)inv[i] * i % mod;
  Rep(i, 1, W + B) {
    write(((1ll + mod + mod - prb - prw) * 500000004ll + prw) % mod);
    prb = (prb + (ll)power(2, mod - 1 - i) * C(i - 1, B - 1)) % mod;
    prw = (prw + (ll)power(2, mod - 1 - i) * C(i - 1, W - 1)) % mod;
  }
  flush();
}

int main() {
  file();
  init();
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#define Rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define Repe(i, a, b) for (register int i = (a); i >= (b); --i)
#define rep(i, a, b) for (register int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define mx(a, b) (a > b ? a : b)
#define mn(a, b) (a < b ? a : b)
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;
using namespace std;

namespace IO {
const uint32 Buffsize = 1 << 15, Output = 1 << 24;
static char Ch[Buffsize], *S = Ch, *T = Ch;
inline char getc() {
  return ((S == T) && (T = (S = Ch) + fread(Ch, 1, Buffsize, stdin), S == T)
              ? 0
              : *S++);
}
static char Out[Output], *nowps = Out;

inline void flush() {
  fwrite(Out, 1, nowps - Out, stdout);
  nowps = Out;
}

template <typename T> inline void read(T &x) {
  x = 0;
  static char ch;
  T f = 1;
  for (ch = getc(); !isdigit(ch); ch = getc())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getc())
    x = x * 10 + (ch ^ 48);
  x *= f;
}

template <typename T> inline void write(T x, char ch = '\n') {
  if (!x)
    *nowps++ = '0';
  if (x < 0)
    *nowps++ = '-', x = -x;
  static uint32 sta[111], tp;
  for (tp = 0; x; x /= 10)
    sta[++tp] = x % 10;
  for (; tp; *nowps++ = sta[tp--] ^ 48)
    ;
  *nowps++ = ch;
  if (nowps - Out >= 1 << 23)
    flush();
}
} // namespace IO
using namespace IO;

void file() {
#ifndef ONLINE_JUDGE
  FILE *DSD = freopen("water.in", "r", stdin);
  FILE *CSC = freopen("water.out", "w", stdout);
#endif
}

inline void Chkmin(int &u, int v) { u > v ? u = v : 0; }

inline void Chkmax(int &u, int v) { u < v ? u = v : 0; }

inline void Chkmax(ll &u, ll v) { u < v ? u = v : 0; }

inline void Chkmin(ll &u, ll v) { u > v ? u = v : 0; }

const int MAXN = 2e5 + 7, mod = 1e9 + 7;

static int fac[MAXN], inv[MAXN];

inline int power(int u, int v) {
  register int sm;
  for (sm = 1; v; v >>= 1, u = (ll)u * u % mod)
    if (v & 1)
      sm = (ll)sm * u % mod;
  return sm;
}

static int B, W;

inline void init() { read(B), read(W); }

inline int C(int u, int v) {
  return u < v ? 0 : (ll)fac[u] * inv[v] % mod * inv[u - v] % mod;
}

static int prb, prw;

inline int ad(int u, int v) { return (u += v) >= mod ? u - mod : u; }

inline void solve() {
  fac[0] = 1;
  Rep(i, 1, W + B) fac[i] = (ll)fac[i - 1] * i % mod;
  inv[W + B] = power(fac[W + B], mod - 2);
  Repe(i, W + B, 1) inv[i - 1] = (ll)inv[i] * i % mod;
  Rep(i, 1, W + B) {
    write(((1ll + mod + mod - prb - prw) * 500000004ll + prw) % mod);
    prb = (prb + (ll)power(2, mod - 1 - i) * C(i - 1, B - 1)) % mod;
    prw = (prw + (ll)power(2, mod - 1 - i) * C(i - 1, W - 1)) % mod;
  }
  flush();
}

int main() {
  init();
  solve();
  return 0;
}