Hello ,this is my submission for problem 1926D - Vlad and Division:325526745 its showing accepted when i use a map ,but when i was previously using unordered_map ,it was giving TLE ,can anyone explain me why ?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3857 |
| 2 | jiangly | 3810 |
| 3 | maroonrk | 3534 |
| 4 | tourist | 3528 |
| 5 | Kevin114514 | 3510 |
| 6 | turmax | 3411 |
| 7 | Um_nik | 3387 |
| 8 | Radewoosh | 3367 |
| 9 | heuristica | 3322 |
| 10 | strapple | 3317 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | maspy | 150 |
| 3 | Um_nik | 145 |
| 4 | Errichto | 139 |
| 5 | adamant | 136 |
| 6 | maroonrk | 134 |
| 7 | DNR | 133 |
| 7 | nik_exists | 133 |
| 9 | AmShZ | 130 |
| 10 | Dominater069 | 129 |
Hello ,this is my submission for problem 1926D - Vlad and Division:325526745 its showing accepted when i use a map ,but when i was previously using unordered_map ,it was giving TLE ,can anyone explain me why ?
| Name |
|---|



original article
article new
Basicly "hackers" can engineer test set that blows up your unordered map into O(N) for every hash
the worst-case time complexity of unordered_map is O(n) per operation due to hash collisions, especially if the input is crafted to cause them. That’s likely why it TLE’d, while map with guaranteed O(log n) stayed safe.
use map<int,int> for a uniform balanced BST resulting in O(logN) for insertion and retrieval of values per key ,while for an unordered_map<int,int> it uses hash fns which provides O(1) amortised but in worst cases O(N) resulting in excessive hash collisions due to weak hash implemented on it , if you wanna use Unordered_map use it with a custom hash
and use it like unordered_map<int,int,custom_hash>X ;