intSolution::solve(vector<int> &A, int B){ if(B == 0) { int now = 0; int res = 0; for(auto& a : A) { if(a & 1) now = 0; else now += 1; res += now; } return res; } vector<int> st{-1}; for(int i = 0; i < A.size(); i++) if(A[i] & 1) st.push_back(i); st.push_back(A.size()); int res = 0; for(int i = B; i < st.size() - 1; i++) { int l = st[i - B + 1] - st[i - B]; int r = st[i + 1] - st[i]; res += l * r; } return res; }