一个比较经典的题目,思路详情可看:【1月17日 牛客每日一题】
#include <bits/stdc++.h>
#define il inline
#define double long double
using namespace std;
using ll = long long;
using ull = unsigned long long;
using int128 = __int128_t;
const ll N = 2e5 + 5, mod = 1e9+7, inf = 2e18;
const double eps = 1e-9;
double PI = 3.1415926;
il void solve(){
int n;
cin>>n;
ll ans=0,idx=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x&1){
ans+=i;
idx=i;
}else{
ans+=idx;
}
}
cout<<ans;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--){
solve();
}
return 0;
}

京公网安备 11010502036488号