Подмассив подсчета имеет неотрицательную сумму ⇐ C++
Подмассив подсчета имеет неотрицательную сумму
Is there any optimal solution (better than O(n^2) to count sub-arrays have non-negative sum?
I've try by using prefix sum and set to count the number of the subarray but it meets TLE because time complexity of distance function is linear:
multiset a for(int i=1;i>tmp; sum=sum[i-1]+tmp; } ll ans=0; for(int i=1;i0) { auto it = a.upper_bound(sum); ans+=(distance(a.begin(),it; } if(sum>=0) ++ans; a.insert(sum); }
Источник: https://stackoverflow.com/questions/780 ... gative-sum
Is there any optimal solution (better than O(n^2) to count sub-arrays have non-negative sum?
I've try by using prefix sum and set to count the number of the subarray but it meets TLE because time complexity of distance function is linear:
multiset a for(int i=1;i>tmp; sum=sum[i-1]+tmp; } ll ans=0; for(int i=1;i0) { auto it = a.upper_bound(sum); ans+=(distance(a.begin(),it; } if(sum>=0) ++ans; a.insert(sum); }
Источник: https://stackoverflow.com/questions/780 ... gative-sum
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как вернуть подмассив непрерывного подмассива наименьшей суммы, а не сумму?
Anonymous » » в форуме JAVA - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вернуть подмассив непрерывного подмассива наименьшей суммы, а не сумму?
Anonymous » » в форуме JAVA - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вернуть подмассив непрерывного подмассива наименьшей суммы, а не сумму?
Anonymous » » в форуме JAVA - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как вернуть подмассив непрерывного подмассива наименьшей суммы, а не сумму?
Anonymous » » в форуме JAVA - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-