C2361 Hugo's Lego

Use a multiset to store the lego sizes (can be duplicate). Use multiset's methods for insertion and deletion.

For $k$'th largest/smallest queries, notice that $1 \le k \le 10$ (quite small). We can get the iterator to the first/last element and then increment/decrement $k$ times.

C2362 - Sunny's Garden

Notice there isn't enough memory to create a $N \times N$ array. Since there will be at most $Q$ plants, we can use a map<pair<int, int>, string> to map coordinates to plants.

Additionally, we also create a map<string, int> to keep track of the number of each plant to answer type 2 queries.

Every time we process a type 1 query, update the number of the plant being grown and the one being replaced (if any).

C2363 - Funny Sorting

Pass a custom comaparator to the built-in sort function.