Reputation: 95
I used unordered_map<long long int, long long int> the key may take values of upto 1e9, this lead to my answer being Time Limit Exceeded.
when I used map<long long int, long long int> it was succesful.
I came to know from other answers that unordered_map is bad when hash function is bad , is there a way to change the hash function of this unordered_map?
Upvotes: 1
Views: 745
Reputation: 1217
I think there might be another cause to this.
If there are more insertions and deletions as compared to lookups, then map
is faster. However, if there are more lookups, then unordered_map
should provide a performance boost.
Have a look at this: https://stackoverflow.com/questions/2196995/is-there-any-advantage-of-using-map-over-unordered-map-in-case-of-trivial-keys#:~:text=map%20just%20has%20a%20few,it%20lacks%20the%20large%20array.
PS: Could you share the question once, for a greater insight?
Upvotes: 1
Reputation: 586
Yes, you are free to do so.
The third template parameter of std::unordered_map
is the hash function going to be used, and it should be a functor that satisfy the requirement listed here.
Upvotes: 2