Hello CodeForces. Offensively that round #383 was rescheduled.
Please help me with this problem.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
Hello CodeForces. Offensively that round #383 was rescheduled.
Please help me with this problem.
Название |
---|
Removing some room (say we want to remove the K-th room in the current configuration) can be split into two phases — first, we find at which initial index would the K-th room in the current configuration be, say that's index P, and then we say that the room at index P is removed. Obviously, answering a query of type 'L' can be done by just running the first phase of what I explained above.
Now, let's see how we can implement these phases. Suppose that up to now, we know which indices were already removed and we want to find the index of the K-th available room in the current configuration. This can be done using a binary search since this index P is the smallest P, for which P - count(P) ≥ K. Here count(i) is the number of rooms we have already removed, having indices less than or equal to i. Once we have found this index P, we just mark it as removed.
The only question that remains, is how we mark some index as removed and how we find count(i) fast enough. Well, that's pretty much what any BST does, my choice was to use treap. Sorry, I was too lazy to code one so I just copied one of my previous implementations. Here is my accepted code.
You can also find k-th available room with segment tree in log(1e9).
My first submission was a dynamic Fenwick tree, which got MLE. Yours is also close to the limit while my solution is far away from it. That's why I explained the solution with treap. The topmost solution uses your code and the one below it is my own.
P_Nyagolov _index -> Thank you =D