3
using pi = pair<int, int>;4
int totalSteps(vector<int> &nums) {7
vector<pi> del; // stores pairs of (previous id, toDelete id)8
for (int i = 0; i < N; ++i) {10
if (i + 1 < N && nums[i] > nums[i + 1]) del.emplace_back(i, i + 1);13
int ans = 0; // number of rounds14
while (!del.empty()) {16
vector<pi> nxt; // pairs to delete in the next round17
for (auto [i, j] : del) mp.erase(j); // first, get rid of the required deletions18
for (auto [i, j] : del) {20
if (it == end(mp) || next(it) == end(mp)) // if it's not in the map anymore,21
continue; // OR if it's the last element, skip it22
auto itn = next(it); // now compare against next element in the ordering23
if (it->second > itn->second)24
nxt.emplace_back(it->first,25
itn->first); // add the (current id, toDelete id)27
swap(nxt, del); // nxt is the new del