注意到:只要区间内有一个奇数,那异或的结果就为奇数。
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
long long ans=0;
int last_1=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x&1)last_1=i;
ans+=last_1;
}
cout<<ans<<endl;
return 0;
}

京公网安备 11010502036488号