Hello Codeforces, yesterday I have submitted various solutions for problem C. Although I have estimated my time and memory complexity to be O(n log n) I was surprised to see that it gave time limit exceeded, can you help me? 188111812
№ | Пользователь | Рейтинг |
---|---|---|
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 | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello Codeforces, yesterday I have submitted various solutions for problem C. Although I have estimated my time and memory complexity to be O(n log n) I was surprised to see that it gave time limit exceeded, can you help me? 188111812
Название |
---|
std upper bound is linear on sets, use set::upper_bound instead
Oh wow! That got AC. Why does this happen? Are there any other functions I need to be cautious when using? Thank you very much for your reply.
lower_bound()
:D
You called a general function
std::upper_bound
. The way this function works is: if it is called on random access iterator, such asstd::vector<int>::iterator
, a binary search is performed, achieving $$$O(\log n)$$$ (since it is possible to access any position in constant time). Otherwise, if the iterator is not random access (such asstd::set<int>::iterator
),std::upper_bould
can't do any better than to just advance the iterator linearly to find the answer.On the other hand,
std::set<int>::upper_boupd
has access to the inner workings of set, which is a binary search tree, so it can go up and down the tree in a smart way to get the answer in $$$O(\log n)$$$.Thank you so much!
downvoted. upper blund is not the problem. optimization is the issue.
please get your facts straight. The problem was clearly upper_bound