https://leetcode-cn.com/problems/sum-of-all-odd-length-subarrays/
class Solution {
public:
int sumOddLengthSubarrays(vector<int>& arr)
{
vector<int>ve; ve.push_back(0);
int sum=0;
for(int i=0;i<arr.size();i++)
{
sum+=arr[i];
ve.push_back(sum);
}
int ans=0;
for(int len=1;len<ve.size();len+=2)
{
for(int i=1;i+len-1<ve.size();i++)
{
int l=i,r=i+len-1;
ans+=ve[r]-ve[l-1];
}
}
return ans;
}
};