DokjaKim's blog

By DokjaKim, history, 53 minutes ago, In English

Learn the properties, not the syntax

Most beginners waste time on implementation details. The real unlock is knowing what each container guarantees:

  • std::set — Stores unique elements, always sorted, $$$\mathcal{O}(\log n)$$$ insert/lookup. Use when you need deduplication or sorted order.
  • std::map — Key-value pairs, sorted by key, $$$\mathcal{O}(\log n)$$$. Use when you need to count/track something indexed by a value.
  • std::unordered_map — Key-value pairs, $$$\mathcal{O}(1)$$$ average lookup, no order. Use when order doesn't matter and you need raw speed.
  • std::priority_queue — Max element at the top, $$$\mathcal{O}(\log n)$$$ insert/pop. Use when you repeatedly need the largest (or smallest) element.

Real Examples

  • 1883B — Chemistry — Once you know the core property that "a palindrome can have at most one character with an odd frequency", the problem trivializes. The code writes itself in 10 lines using a frequency map (map<char, int>). No complex algorithm needed.
  • 1904A — Forked! — Once you realize that set intersection is as simple as "put one piece's attack coordinates in a set, then check the other piece's moves against it", all arithmetic gymnastics disappear.

The Core Takeaway

Most CP tutorials focus heavily on teaching complex algorithms. Nobody tells you that knowing upper_bound exists saves you from writing manual binary search, or that finding set intersections is just a simple lookup loop.

That meta-knowledge — knowing what tools exist and when to reach for them — is worth infinitely more than memorizing standard code implementations.

  • Vote: I like it
  • -8
  • Vote: I do not like it

»
18 minutes ago, hide # |
← Rev. 2  
Vote: I like it +3 Vote: I do not like it