Language: C++

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//区間XORと区間和が等しい <=> その区間において二回以上立っているビットがない

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<vector<int>> B(20, vector<int>(N, 0)), S(20, vector<int>(N+1, 0));
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		for (int j = 0; j < 20; j++) {
			if (A[i] & (1 << j))B[j][i]++;
		}
	}
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < N; j++) {
			S[i][j + 1] = S[i][j] + B[i][j];
		}
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll tmp = INF;
		for (int j = 0; j < 20; j++) {
			auto itr = upper_bound(S[j].begin(), S[j].end(), S[j][i] + 1);
			tmp = min(tmp, itr - S[j].begin() - i - 1);
		}
		ans += tmp;
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:34: error: no matching function for call to 'min(ll&, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
   36 |                         tmp = min(tmp, itr - S[j].begin() - i - 1);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:36:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
   36 |                         tmp = min(tmp, itr - S[j].begin() - i - 1);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:36:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   36 |                         tmp = min(tmp, itr - S[j].begin() - i - 1);
      |                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~