Hello everyone, I was solving problem C of a div 3 contest 1702C - Train and Queries and I just used 2 hash maps to stores the first and last occurence of each station, but on test case 45 its saying TLE.
Then i read the editorial and tried to using just one hashmap but still it says TLE.
Please Help.
Only replace unordered_map with map
map: 165985542
unordered map: 165981690
and after adding fast I/O it will work in 576 ms instead of 2043 ms.
Fast I/O code: 165987488
May be due to slow I/O. Please try to add ios_base::sync_with_stdio(false); cin.tie(nullptr); at the beginning.
worst case complexity of searching, insertion, deletion in
std::unordered_map
is $$$O(n)$$$- How to save yourself from getting hacked?
You can read the full thing here.
- Over 350 hacks by beethoven97 on this one problem
You can see many people got hacked in that contest due to this same issue.