From e28d832f2605b63b3d0caacb9c62fd235031ba7d Mon Sep 17 00:00:00 2001 From: Michael Zegar <85312805+3centroids@users.noreply.github.com> Date: Wed, 24 Jan 2024 09:54:20 +0100 Subject: [PATCH] Update sqrt_decomposition.md the sentence sounded unnatural --- src/data_structures/sqrt_decomposition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data_structures/sqrt_decomposition.md b/src/data_structures/sqrt_decomposition.md index 7362733f7..ff9c3e351 100644 --- a/src/data_structures/sqrt_decomposition.md +++ b/src/data_structures/sqrt_decomposition.md @@ -106,7 +106,7 @@ Sqrt decomposition can be applied in a similar way to a whole class of other pro Another class of problems appears when we need to **update array elements on intervals**: increment existing elements or replace them with a given value. -For example, let's say we can do two types of operations on an array: add a given value $\delta$ to all array elements on interval $[l, r]$ or query the value of element $a[i]$. Let's store the value which has to be added to all elements of block $k$ in $b[k]$ (initially all $b[k] = 0$). During each "add" operation we need to add $\delta$ to $b[k]$ for all blocks which belong to interval $[l, r]$ and to add $\delta$ to $a[i]$ for all elements which belong to the "tails" of the interval. The answer a query $i$ is simply $a[i] + b[i/s]$. This way "add" operation has $O(\sqrt{n})$ complexity, and answering a query has $O(1)$ complexity. +For example, let's say we can do two types of operations on an array: add a given value $\delta$ to all array elements on interval $[l, r]$ or query the value of element $a[i]$. Let's store the value which has to be added to all elements of block $k$ in $b[k]$ (initially all $b[k] = 0$). During each "add" operation we need to add $\delta$ to $b[k]$ for all blocks which belong to interval $[l, r]$ and to add $\delta$ to $a[i]$ for all elements which belong to the "tails" of the interval. The answer to query $i$ is simply $a[i] + b[i/s]$. This way "add" operation has $O(\sqrt{n})$ complexity, and answering a query has $O(1)$ complexity. Finally, those two classes of problems can be combined if the task requires doing **both** element updates on an interval and queries on an interval. Both operations can be done with $O(\sqrt{n})$ complexity. This will require two block arrays $b$ and $c$: one to keep track of element updates and another to keep track of answers to the query.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: