Internally, set items are stored in a balanced binary tree. A balanced tree is a tree in which the maximum height difference between any left and right subtree of any node is 1.
Maintaining a balanced structure is important to ensure that finding any item in a tree (in a set) in the worst case O(log(n)) steps.
Removing an item may upset the balance. To restore balance, rotations must be performed. In some cases, one deletion leads to several turns, so the operation takes O(log(n)) steps, but on average it takes O(1) steps.
Thus, when several items scattered across a set must be deleted one after another, the amortized cost is likely to be O(1) for deletion.
Deleting several elements in the range ( first, last , where one element follows the next) will almost certainly destroy the balance, which will make the logarithmic coefficient difficult: log(n) + std::distance(first, last)
source share