ABC170 Issue E Smart Infants 200,000 numbers move around 200,000 times in a set of 200,000 numbers. In this case, find the minimum value of the "set maximum" for each move problem.
Thoughts during the contest Of course, if we did O(N) for each set for each move, we would TLE. You want to quickly retrieve the minimum value, so heapq heap queue. Prioritized queue - Wikipedia Is it?
However, as numbers are moved, values other than the minimum may be removed from the "set of maximum values". Example: {1}, {2}, {3} → {1}, {2, 3}, {} Hmmm, a binary search against a sorted array to find the desired one... no, an add/delete to the array is O(N), so a repeated add/delete attack would make it a TLE.
Lower the cost of adding and deleting by making it a linked list... No, that makes it O(N) to find objects to delete... So make it a bi-directional list and index each object: ????
Solution Discussion section. multiset - C++ Reference Equilibrium binary search tree - Wikipedia I see...I tried to make O(1) out of O(N), and it was "if you make that one stand up, this one won't stand up", but should I make it O(logN) in general? I understand the direction.
So what's the specific implementation... hey, someone's using heapq? https://atcoder.jp/contests/abc170/submissions/14361676 I see. The cost of removing elements other than the head of the heap queue is high, but it's okay if we don't remove them; instead, we can add a mechanism to skip reading them.
So the code I wrote with reference to it became AC. https://atcoder.jp/contests/abc170/submissions/14371172
impressions
I brought the appropriate AVL tree implementation and replaced it. → Code is simplified, but TLE The order should be O(logN), but the constant times larger?
See 5 from the fastest PyPy implementers
Four people heapq to have individual sets. the number is so large that tree construction is probably avoided because of the overhead. The approach of skipping reads instead of doing deletions seems to be widely used. Only one person was using a set, or hashmap approach. A surprising loophole.
There are 3 segment trees, 1 heapq, and 1 fennic tree to have the largest set of values. The Fennic tree looks interesting, but I'm inclined to be able to use the segment tree for now.
https://atcoder.jp/contests/abc170/submissions/14369529
https://atcoder.jp/contests/abc170/submissions/14332420
https://atcoder.jp/contests/abc170/submissions/14338427
https://atcoder.jp/contests/abc170/submissions/14349092
https://atcoder.jp/contests/abc170/submissions/14360320
based on this
This page is auto-translated from [/nishio/ABC170 E](https://scrapbox.io/nishio/ABC170 E) using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.