http://mirror.codeforces.com/contest/512/problem/B
solution id : 12300691 and 12300696 http://mirror.codeforces.com/submissions/arbit
unordered_map is giving wrong answers while map gives the correct answer.
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
http://mirror.codeforces.com/contest/512/problem/B
solution id : 12300691 and 12300696 http://mirror.codeforces.com/submissions/arbit
unordered_map is giving wrong answers while map gives the correct answer.
Name |
---|
Looks like you use fact, that in map all pairs are sorted. It's true for normal map(because it's based on BST), but wrong for unordered_map(because it's based on hash table and keys are sorted not by value, but by hashs)
According to the solution, the ordered property is not making any difference.
Ok, that's my error :(
Here
You can add element to map. Maybe it can make iterator it1 invalid...
According to what you are saying, map should give wrong answers however it is the other way round.
When you change container there are magic with iterators, so it's better just not to do it :) You can never be sure what you will get
std::map
andstd::unordered_map
have different iterator invalidation rules. Basically, anystd::unordered_map
iterator can be invalidated after any insertion or deletion because of rehashing, and you can't control it. On other hand,std::map
iterator is guaranteed to be valid until you erase it explicitly. That's why you got 2 different results.