Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя nine.nine

Автор nine.nine, история, 4 года назад, По-английски

If I use unordered_map<int,multiset> to store the values, it gives a TLE. In the same code, if I change it to unordered_map<int,vector>, and sort the map's value when taken into use (to act like multiset), doesn't give a TLE. How/Where is the time complexity different for both ?

P.S. — Pardon me if I did not follow the conventions of a blog, this being the first one. Would be happy to know about my mistakes.

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The constant factor of unordered_map is better than that of map.

You can use PBDS hash tables for even faster performance.

»
4 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

multiset has insert in $$$O(log(n))$$$, while vector has O(1) push_back. Multiset insert, Vector push_back