Problem p03051 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <tr1/unordered_map>
#define ll long long
#define maxn 100010
#define maxa (1 << 21)
#define mod 1000000007
using namespace std;
using namespace tr1;
inline int getint() {
  char c = getchar();
  int x = 0;
  bool p = 0;
  while ((c > '9' || c < '0') && c != '-')
    c = getchar();
  if (c == '-')
    p = 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  if (p)
    x = -x;
  return x;
}
int n, a[maxn], s1[maxa << 3], s2[maxa << 3], tg[maxa << 3];
inline void pushup(int o) {
  s1[o] = (s1[o << 1] + s1[o << 1 | 1]) % mod;
  s2[o] = (s2[o << 1] + s2[o << 1 | 1]) % mod;
}
inline void build(int o, int l, int r) {
  tg[o] = 0;
  if (l == r) {
    s1[o] = 1;
    s2[o] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
  pushup(o);
}
inline void gao(int o, int x) {
  s1[o] = (s1[o] + 1ll * x * s2[o]) % mod;
  tg[o] = (tg[o] + x) % mod;
}
inline void pushdown(int o) {
  gao(o << 1, tg[o]), gao(o << 1 | 1, tg[o]);
  tg[o] = 0;
}
inline void update(int o, int l, int r, int x, int p) {
  if (l == r) {
    if (p == n)
      cout << s1[o] << endl;
    s2[o] = (s2[o] + s1[o]) % mod;
    return;
  }
  pushdown(o);
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(o << 1, l, mid, x, p);
  else
    update(o << 1 | 1, mid + 1, r, x, p);
  pushup(o);
}
int main() {
  n = getint();
  for (int i = 1; i <= n; ++i)
    a[i] = getint(), a[i] ^= a[i - 1];
  build(1, 1, maxa);
  int sum = 1;
  for (int i = 1; i <= n; ++i) {
    if (!a[i]) {
      if (i == n)
        cout << (s2[1] + sum) % mod << endl;
      sum = 1ll * sum * 2 % mod;
      gao(1, 1);
    } else
      update(1, 1, maxa, a[i], i);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <tr1/unordered_map>
#define ll long long
#define maxn 500050
#define maxa (1 << 21)
#define mod 1000000007
using namespace std;
using namespace tr1;
inline int getint() {
  char c = getchar();
  int x = 0;
  bool p = 0;
  while ((c > '9' || c < '0') && c != '-')
    c = getchar();
  if (c == '-')
    p = 1, c = getchar();
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  if (p)
    x = -x;
  return x;
}
int n, a[maxn], s1[maxa << 3], s2[maxa << 3], tg[maxa << 3];
inline void pushup(int o) {
  s1[o] = (s1[o << 1] + s1[o << 1 | 1]) % mod;
  s2[o] = (s2[o << 1] + s2[o << 1 | 1]) % mod;
}
inline void build(int o, int l, int r) {
  tg[o] = 0;
  if (l == r) {
    s1[o] = 1;
    s2[o] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
  pushup(o);
}
inline void gao(int o, int x) {
  s1[o] = (s1[o] + 1ll * x * s2[o]) % mod;
  tg[o] = (tg[o] + x) % mod;
}
inline void pushdown(int o) {
  gao(o << 1, tg[o]), gao(o << 1 | 1, tg[o]);
  tg[o] = 0;
}
inline void update(int o, int l, int r, int x, int p) {
  if (l == r) {
    if (p == n)
      cout << s1[o] << endl;
    s2[o] = (s2[o] + s1[o]) % mod;
    return;
  }
  pushdown(o);
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(o << 1, l, mid, x, p);
  else
    update(o << 1 | 1, mid + 1, r, x, p);
  pushup(o);
}
int main() {
  n = getint();
  for (int i = 1; i <= n; ++i)
    a[i] = getint(), a[i] ^= a[i - 1];
  build(1, 1, maxa);
  int sum = 1;
  for (int i = 1; i <= n; ++i) {
    if (!a[i]) {
      if (i == n)
        cout << (s2[1] + sum) % mod << endl;
      sum = 1ll * sum * 2 % mod;
      gao(1, 1);
    } else
      update(1, 1, maxa, a[i], i);
  }
  return 0;
}