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 | 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 |
# | User | Contrib. |
---|---|---|
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 |
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.