In the Contest Codeforces Round #843 (Div. 2) Problem B. Gardener and the Array I got TLE for the Code in Which I used a Vector of size 200007 vector p(200007, 0); and after contest I tried Submitting the same solution using Map in place of vector map<int, int>p; and the solution got accepted, The Time Complexity of Both the codes is O(N). Seriously Vector takes less time than map and I don't know why and how can a Map beat Vector in TC. If anyone know the reason behind this please explain. Thank you for your time.
Both the submissions 1) Using Vector: 188741557 2) Using Map: 188778187
After Seeing Solution of Map getting Accepted I was quite enraged, as in some contests for some problem I got TLE because of using Map instead of Vector and This time I didn't think of Map and it satisfied the TC. Please explain the reason behind this and when should we use map and vector when both data structures can be used.
Edit: Got the reason behind TLE, Due to initialization of vector I got TLE as it takes additional 2e5 for initialization to 0 every time. Cant get over it Emotional Damage ;-;




