Hello , can any one please explain how to get the value of key of type pair<int,int> .

i.e map<pair<int,int>,int> ? I am getting an error

And also can anyone please explain when to use map and unordered_map ?

Thanks in advance

Hello , can any one please explain how to get the value of key of type pair<int,int> .

i.e map<pair<int,int>,int> ? I am getting an error

And also can anyone please explain when to use map and unordered_map ?

Thanks in advance

you need to define a hash function in unordered_map when you use pairs

1 Like

you can access the value like this-

map<pair<int,int>,int>mp;

cout<<mp[{x,y}];

where {x,y} is the pair

3 Likes

or use auto

2 Likes

Yeah , i was using unordered_map . Thanks btw !!

1 Like

You might also want to go through this article. It’s also gonna help if you don’t want to get hacked in CodeForces competitions. In fact, quite a few participants (including me) got their asses handed to them in this contest, in this problem for using `unordered_map`

/ `unordered_set`

’s default hash function.

2 Likes

That was a really cool article; thanks!

1 Like

Thanks a lot bro !

1 Like