天天看点

有趣的区间

https://ac.nowcoder.com/acm/contest/11220/D
#include<bits/stdc++.h>

using namespace std;

#define int long long
const double eps = 1e-6;
const int N = 5e5 + 10;

int n;
int a[N];

void solve() {
    cin >> n;
    for (int i =0; i< n ;i ++) {
          cin >> a[i]; a[i] %= 2;
    }
    int ans = (n + 1) * n / 2;
    int c  = 0;
     for (int i = 0; i< n; i ++) {
         if (a[i]) {
             ans -= c * (c + 1) / 2;
             c = 0;
         }
         else c ++;
     }
    ans -= c * (c + 1) / 2;
    cout << ans <<endl;
}
signed main () {
    int t;
    t =1;
    while(t --) solve();
}      

继续阅读