Why unordered_set and unordered_map are giving me TLE but lower bound isn't.

Revision en1, by Chiefash, 2023-12-05 00:05:39

I was trying to solve problem C in Educational Codeforces Round 159 (Rated for Div. 2).

Here I just wanted to check if the value i is not present in the array. I tried using three things 1. I created an unordered_set of all elements in the array and used !s.count(i) to check if the value is present or not? 2. I created an unordered_map of all elements in the array and used mp[i] == 0 to check if the value is present or not 3. Finally I used lower_bound function on the array to check if the value is present or not.

I got TLE on first two but accepted in third. Can someone please explain why is this happening. I don't want to make the same mistake again in the contest.

I am adding images for all examples.

Tags unordered_map, unordered_set, binary search, doubt

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Chiefash 2023-12-05 00:07:09 233
en1 English Chiefash 2023-12-05 00:05:39 812 Initial revision (published)