Why does this code is RTE ?!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Название |
---|
Your comparison function is incorrect. For example it returns
true
for 0 and 0 which should never happen for correctless than
comparison.That's true but what's the problem ? If two equal values are swapped in the array it will cauz no effect.
Well first of all, even this is already enough according to C++ standard to lead to undefined behaviour so you can't expect anything after doing sort like that. But in reality I think your comparison function acts very weird in other cases too, like:
I don't think it can be well defined what sort should do in this case.
C++ assumes that your comparator is strict "less than" operator, not the "less than or equal to". So the followings must be satisfied, otherwise you'll get weird result.
1) if func(a, b) is true, then func(b, a) must be false 2) if func(a, b) and func(b, c) is true, then func(a, c) must be true 3) func(a, a) must be false