Problem p03051 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144 * 4
#define REP(a, b) for (long long a = 0; a < b; ++a)
long long grid[600000] = {};
vector<long long> finding_X[2000000];
long long zero[600000] = {};
long long cnt_zero(long long l, long long r) {
  long long ans = zero[r];
  if (l != 0) {
    ans -= zero[l - 1];
  }
  return ans;
}
pair<long long, long long> calc(long long X) {
  pair<long long, long long> ans = make_pair(1, 0);
  if (finding_X[X].size() != 0) {
    ans.second = 1;
  }
  for (int i = 1; i < finding_X[X].size(); ++i) {
    long long zero_move = cnt_zero(finding_X[X][i - 1], finding_X[X][i]);
    ans.first += zero_move * ans.second;
    ans.first %= MAX_MOD;
    ans.second += ans.first;
    ans.second %= MAX_MOD;
  }
  return ans;
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  REP(i, n) {
    cin >> grid[i + 1];
    grid[i + 1] ^= grid[i];
  }
  for (int i = 1; i <= n; ++i) {
    zero[i] = zero[i - 1];
    if (grid[i] == 0) {
      zero[i]++;
    } else {
      finding_X[grid[i]].push_back(i);
    }
  }
  if (grid[n] != 0) {
    cout << calc(grid[n]).first << endl;
    return 0;
  }
  assert(0 == 1);
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define MOD 998244353LL
#define seg_size 262144 * 4
#define REP(a, b) for (long long a = 0; a < b; ++a)
long long grid[600000] = {};
vector<long long> finding_X[2000000];
long long zero[600000] = {};
long long cnt_zero(long long l, long long r) {
  long long ans = zero[r];
  if (l != 0) {
    ans -= zero[l - 1];
  }
  return ans;
}
pair<long long, long long> calc(long long X) {
  pair<long long, long long> ans = make_pair(1, 0);
  if (finding_X[X].size() != 0) {
    ans.second = 1;
  }
  for (int i = 1; i < finding_X[X].size(); ++i) {
    long long zero_move = cnt_zero(finding_X[X][i - 1], finding_X[X][i]);
    ans.first += zero_move * ans.second;
    ans.first %= MAX_MOD;
    ans.second += ans.first;
    ans.second %= MAX_MOD;
  }
  return ans;
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  REP(i, n) {
    cin >> grid[i + 1];
    grid[i + 1] ^= grid[i];
  }
  for (int i = 1; i <= n; ++i) {
    zero[i] = zero[i - 1];
    if (grid[i] == 0) {
      zero[i]++;
    } else {
      finding_X[grid[i]].push_back(i);
    }
  }
  if (grid[n] != 0) {
    cout << calc(grid[n]).first << endl;
    return 0;
  }
  long long ans = 1;
  for (int i = 0; i < zero[n] - 1; ++i) {
    ans *= 2;
    ans %= MAX_MOD;
  }
  for (int i = 1; i < (1 << 20); ++i) {
    ans += calc(i).second;
    ans %= MAX_MOD;
  }
  cout << ans << endl;
}