of array – a sequence of one or more
consecutive elements in array.D-good segment – segment, in which sum of elements not greater than D.
Count the pairs (L, R) such that segment [L, R] of array A is D-good.
FindSlide.org - это сайт презентаций, докладов, шаблонов в формате PowerPoint.
Email: Нажмите что бы посмотреть
O(N3)
O(N2)
O(NlogN)
int right = -1;
int sum = 0;
for (int i = 0; i < n; ++i)
{
while (right + 1 < n && sum + a[right + 1] <= d)
sum += a[++right];
ans += right - i + 1;
sum -= a[i];
}
O(N)