Map O(nlogn) Python
\nfrom sortedcontainers import SortedList as sl\nclass Solution:\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        ans = [-1]*(len(rains))\n   
```\nfrom sortedcontainers import SortedList as sl\nclass Solution:\n    def avoidFlood(self, rains: List[int]) -> List[int]:\n        ans = [-1]*(len(rains))\n        has_rained = dict()\n        free = sl()\n        for i in range(len(rains)):\n            # print(free)\n            if rains[i]==0:\n                free.add(i)\n            else:\n                if rains[i] not in has_rained:\n                    has_rained[rains[i]]=i\n                else:\n\t\t\t\t\t# no free days are available\n                    if len(free)==0:\n                        return []\n\t\t\t\t\t#finding the index of the free day that came after the first occurance of\n\t\t\t\t\t# rains[i]\n                    idx = free.bisect_left(has_rained[rains[i]])\n                    # print(free,idx,i,has_rained)\n                    if idx<len(free):\n                        ans[free[idx]]=rains[i]\n\t\t\t\t\t\t# updating the index of rains[i] for future it\'s future occurances\n                        has_rained[rains[i]] = i\n                        free.remove(free[idx])\n                    else:\n\t\t\t\t\t\t#if no such index exists then return\n                        return []\n        if len(free):\n            while free:\n\t\t\t\t# choosing some day to dry on the remaining days\n                ans[free.pop()]=1\n        return ans\n```
['Greedy', 'Python3']