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

Правка en2, от Chiefash, 2023-12-05 00:07:09

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.

image1 image2 image3

Теги unordered_map, unordered_set, binary search, doubt

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Chiefash 2023-12-05 00:07:09 233
en1 Английский Chiefash 2023-12-05 00:05:39 812 Initial revision (published)