Skip to content
Embercode
✕
Range queries and tricksQuick quiz

Segment trees and offline sweeps

7 questions. Covers Offline queries and sorting.

Questions 1 to 5 of 7

  1. 1. An AI wrote a max-subarray segment tree with the identity {sum 0, best prefix 0, best suffix 0, best 0}. A query on the range [-3, -1, -2] returns 0. What is wrong?
  2. 2. Which properties does a segment tree need from its merge operation, to answer range queries with a bottom-up or recursive layout?

    Pick every answer that is true.

  3. 3. A node has a pending tag "add 10", written as the map f = (1, 10), meaning x -> 1 * x + 10. Then a new tag "assign 7" arrives, written as g = (0, 7). The rule for composing is: the old tag goes first, so the combined map is (g.a * f.a, g.a * f.b + g.b). Apply the combined tag to a child value of 1. What is the result?

    Type a number.

  4. 4. An AI wrote a lazy segment tree update. When a node only partly overlaps the update range, its code calls the two children first, then pushes the node's pending tag to them. What goes wrong?
  5. 5. Match each part of the offline distinct-count sweep with what it does.

    Choose the matching item for each row.

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.