http://codeforces.net/contest/512/problem/B
solution id : 12300691 and 12300696 http://codeforces.net/submissions/arbit
unordered_map is giving wrong answers while map gives the correct answer.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
http://codeforces.net/contest/512/problem/B
solution id : 12300691 and 12300696 http://codeforces.net/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.