Learn C++ STL

Lesson 5 of 9 · The STL in Competitive Programming: Which Container for Which Problem

Module 16 · The STL in Competitive Programming: Which Container for Which Problem

Changing Ranks With GCC pb_ds, and What a Plain Set Cannot Promise

ProReading

Maria keeps adding and removing labels from a live shelf. Now she asks for the fifth smallest label and how many labels are below a threshold. A set knows sorted order. That sounds enough, until walking to each answer becomes the expensive part.

Checking what this lesson needs for you…

What is inside Changing Ranks With GCC pb_ds, and What a Plain Set Cannot Promise

  1. This is a GCC extension
  2. Read the typedef one choice at a time
  3. Select a zero-based rank
  4. Count strict predecessors
  5. Updates change ranks, not identities
  6. Subtree sizes make rank queries possible
  7. Keep duplicates with unique ids
  8. Compare the same query across three choices
  9. Run the rank-query lab
  10. Decide whether the extension earns its place