1066C - Books Queries I'm trying to solve this problem using deque, but get WA, can any one tell me why it is wrong 155581257
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
6 | adamant | 157 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
1066C - Books Queries I'm trying to solve this problem using deque, but get WA, can any one tell me why it is wrong 155581257
Название |
---|
== But, unlike vectors, deques are not guaranteed to store all its elements in contiguous storage locations: accessing elements in a deque by offsetting a pointer to another element causes undefined behavior. == I think, you can't use difference of addresses.
Difference of addresses of deque's items surely not to be used. But in code used only differences of iterators, which is correct.
Problem is there: http://open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4861.pdf#subsubsection.22.3.8.4
An insertion at either end of the deque invalidates all the iterators to the deque
. So using stored iterators after push_back/pop_back is UB.Difference of iterators is difference of addresses, as i understand. On non-linear containers metod 'distance()' need to be used to get count of elements between two iterators.
Invalidation will cause troubles as well. So, method 'distance ()' doesn't help to solve the problem.
Nope, difference of iterators is literally answer to question "how many times I need to decrement".
operator-
must be correct for allRandomAccessIterators
. Deque providesRandomAccessIterator
. It not just pointer but more complex struct.Ok, agree. Thank you.
Thank you.