Problem p02838 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i, n) for (long long i = 0; i < n; i++)
#define repr(i, n, m) for (long long i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x)                                                                \
  for (auto &&itr : x) {                                                       \
    debug(itr);                                                                \
  }

template <class T> inline void chmax(T &ans, T t) {
  if (t > ans)
    ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
  if (t < ans)
    ans = t;
}

ll digit[100010][70][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  vector<ll> two(70, 0);
  ll tw = 1;
  ll cnt = 0;
  while (cnt < 62) {
    two[cnt] = tw % MOD;
    tw *= 2;
    cnt++;
  }

  ll n;
  cin >> n;
  vector<ll> a(n);

  rep(i, n) {
    cin >> a[i];
    ll cp = a[i];

    for (int t = 0; t < 70; ++t) {
      if (cp & 1) {
        digit[i + 1][t][1] = (digit[i][t][1] + two[t]) % MOD;
        digit[i + 1][t][0] = (digit[i][t][0]) % MOD;
      } else {
        digit[i + 1][t][1] = (digit[i][t][1]) % MOD;
        digit[i + 1][t][0] = (digit[i][t][0] + two[t]) % MOD;
      }
      cp >>= 1;
    }
  }

  /*for (int i = 0; i < n+1; ++i) {
      for (int j = 0; j < 3; ++j) {
          cout << digit[i][j][0] << " ";
          //cout << digit[i][j][1] << " ";
      }

      cout << endl;
  }*/

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll cp = a[i];
    for (int t = 0; t < 70; ++t) {
      ll one = MOD + digit[n][t][1] - digit[i][t][1];
      ll zero = MOD + digit[n][t][0] - digit[i][t][0];
      // cout << one << " " << zero << endl;
      if (cp & 1) {
        ans += zero % MOD;
      } else {
        ans += one % MOD;
      }

      cp >>= 1;
    }
  }

  cout << ans % MOD << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i, n) for (long long i = 0; i < n; i++)
#define repr(i, n, m) for (long long i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x)                                                                \
  for (auto &&itr : x) {                                                       \
    debug(itr);                                                                \
  }

template <class T> inline void chmax(T &ans, T t) {
  if (t > ans)
    ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
  if (t < ans)
    ans = t;
}

ll digit[300010][70][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  vector<ll> two(70, 0);
  ll tw = 1;
  ll cnt = 0;
  while (cnt < 62) {
    two[cnt] = tw % MOD;
    tw *= 2;
    cnt++;
  }

  ll n;
  cin >> n;
  vector<ll> a(n);

  rep(i, n) {
    cin >> a[i];
    ll cp = a[i];

    for (int t = 0; t < 70; ++t) {
      if (cp & 1) {
        digit[i + 1][t][1] = (digit[i][t][1] + two[t]) % MOD;
        digit[i + 1][t][0] = (digit[i][t][0]) % MOD;
      } else {
        digit[i + 1][t][1] = (digit[i][t][1]) % MOD;
        digit[i + 1][t][0] = (digit[i][t][0] + two[t]) % MOD;
      }
      cp >>= 1;
    }
  }

  /*for (int i = 0; i < n+1; ++i) {
      for (int j = 0; j < 3; ++j) {
          cout << digit[i][j][0] << " ";
          //cout << digit[i][j][1] << " ";
      }

      cout << endl;
  }*/

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll cp = a[i];
    for (int t = 0; t < 70; ++t) {
      ll one = MOD + digit[n][t][1] - digit[i][t][1];
      ll zero = MOD + digit[n][t][0] - digit[i][t][0];
      // cout << one << " " << zero << endl;
      if (cp & 1) {
        ans += zero % MOD;
      } else {
        ans += one % MOD;
      }

      cp >>= 1;
    }
  }

  cout << ans % MOD << endl;
}