Balancing Inversions (2019 US Open Gold)

Link
Editorial link

I was not able to solve this problem, and I can’t seem to understand the editorial. Can someone explain to me what is the solution in the editorial? I understand everything up to “Notice that any sequence of swaps can be interpreted as moving around the 1s in the array…”, can you explain what happens after?

Also, what type of problem is this? It is not in any module of USACO Guide, so I assume it is ad hoc?