The STL Standard Library
The STL: sort, pairs, set and map — tools that save you hours.
The STL (Standard Template Library) is C++'s main advantage in contests. Ready-made data structures and algorithms cover half of all routine subtasks.
The most used one is sorting: std::sort from the algorithm library sorts a vector in O(n log n). In one line.
C++
Sorting. Enter: 5, then 3 1 4 1 5
Note the loop for (int x : a) — this is a "range-for", a short way to visit every element.
Two more indispensable containers:
• std::set — stores elements without duplicates and in sorted order; the "does it contain x" check runs in O(log n);
• std::map — a "key → value" dictionary; perfect for counting how many times each word or number occurs.
C++
Counting occurrences with a map. Enter: 6, then 1 2 2 3 3 3
Task: read n numbers and print how many distinct values there are (hint: put everything into a set and print its size).
Mark the lesson as completed — one final step of the course remains: the contest template.