Embercode
✕
Segment TreesQuick quiz

Compression and merge sort trees

8 questions. Covers Merge sort tree for range order queries.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v{3, 7, 7, 10}; auto lo = std::lower_bound(v.begin(), v.end(), 7) - v.begin(); auto hi = std::upper_bound(v.begin(), v.end(), 7) - v.begin(); std::cout << lo << ' ' << hi << '\n'; } ``
  2. 2. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <vector> int main() { std::vector<long long> adds{1000, 7, 1000, 250}; std::vector<long long> sorted = adds; std::sort(sorted.begin(), sorted.end()); sorted.erase(std::unique(sorted.begin(), sorted.end()), sorted.end()); for (std::size_t i = 0; i < adds.size(); ++i) { auto rank = std::lower_bound(sorted.begin(), sorted.end(), adds[i]) - sorted.begin(); std::cout << rank << (i + 1 < adds.size() ? ',' : '\n'); } } ``
  3. 3. A query on the merge sort tree in lesson 11 visits about 2 log2 n nodes, and each node that lies fully inside the range does one binary search. What is the total time of one query?
  4. 4. Why does the lesson 10 program read every add line before it builds the sorted list of values?
  5. 5. Which statements about the merge sort tree in lesson 11 are true?

    Pick every answer that is true.

5 question(s) left on this page.