---
id: RURQ
title: "Range Update Range Query"
author: Benjamin Qi
prerequisites: 
 - Gold - Point Update Range Query
description: Lazy updates on segment trees and two binary indexed trees in conjunction.
frequency: 1
---

import { Problem } from "../models";

export const metadata = {
  problems: {
    bitSample: [
      new Problem("SPOJ", "Horrible Queries", "HORRIBLE", "Easy", false, ["BIT-Range"], ""),
    ],
    bitProb: [
      new Problem("CSES", "Polynomial Queries", "1736", "Easy", false, ["BIT-Range"], "equivalent to https://dmoj.ca/problem/acc3p4"),
    ],
    lazySample: [
      new Problem("CSES", "Range Updates & Sums", "1735", "Easy", false, ["Lazy SegTree"], ""),
    ],
    lazySegTree: [
      new Problem("YS", "Range Affine Range Sum", "range_affine_range_sum", "Easy", false, ["Lazy SegTree"], ""),
      new Problem("Plat", "Counting Haybales", "578", "Easy", false, ["Lazy SegTree"], ""),
      new Problem("Old Gold", "The Lazy Cow", "418", "Easy", false, ["Lazy SegTree"], ""),
      new Problem("Plat", "Snow-Cow", "973", "Normal", false, ["Lazy SegTree"], "Can use lazy seg in place of two BITs"),
    ],
    lazySegCnt: [
      new Problem("CSES", "Area of Rectangles", "1741", "Normal", false, ["Lazy SegTree"], ""),
      new Problem("HR", "Strange Tree", "https://www.hackerrank.com/contests/openbracket-2017/challenges/special-path-on-a-strange-tree/problem", "Very Hard", false, ["Lazy SegTree"]),
    ],
    segTreeBeats: [
      new Problem("YS", "Range Chmin Chmax Add Range Sum", "range_chmin_chmax_add_range_sum", "Very Hard", false, ["SegTreeBeats"], ""),
    ],
  }
};

## BIT Revisited

<problems-list problems={metadata.problems.bitSample} />

Binary Indexed Trees can support range increments in addition to range sum queries.

### Tutorial

<resources>
  <resource source="GFG" title="Range Update Point Query" url="binary-indexed-tree-range-updates-point-queries/"></resource>
  <resource source="GFG" title="Range Update Range Query" url="binary-indexed-tree-range-update-range-queries/"></resource>
</resources>

[My Implementation](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/1D%20Range%20Queries%20(9.2)/BITrange.h)

### Problems

<problems-list problems={metadata.problems.bitProb} />

## Lazy Segment Tree

<problems-list problems={metadata.problems.lazySample} />

### Tutorial

<resources>
  <resource source="CPH" title="28.1 - Segment Trees Revisited" starred>short description</resource>
  <resource source="CSA" title="Segment Trees" url="segment_trees" starred>interactive</resource>
  <resource source="cp-algo" title="Segment Tree" url="data_structures/segment_tree.html" starred>adding on segments, assigning</resource>
  <resource source="CF" title="Efficient and easy segment trees" url="blog/entry/18051">code is more confusing than recursive version</resource>
</resources>

### Problems

<problems-list problems={metadata.problems.lazySegTree} />

## Lazy Segment Tree - Counting Minimums

use segment tree that keeps track of minimum and # of minimums

(describe)

<problems-list problems={metadata.problems.lazySegCnt} />