C++ using map and emplace.
\nclass Solution {\npublic:\n    vector<int> fallingSquares(vector<vector<int>>& positions) {\n        map<int,int> count = {{-1,0}};\n        int n = positions
```\nclass Solution {\npublic:\n    vector<int> fallingSquares(vector<vector<int>>& positions) {\n        map<int,int> count = {{-1,0}};\n        int n = positions.size();\n        vector<int> ans;\n        int res = 0;\n        for(int i=0;i<n;i++) {\n            auto ed = count.emplace(positions[i][0]+positions[i][1], (--count.upper_bound(positions[i][0]+positions[i][1]))->second);\n            auto st = count.emplace(positions[i][0], (--count.upper_bound(positions[i][0]))->second);\n            int add = 0;\n            for(auto it = st.first;it!=ed.first;it++) {\n                add = max(add, it->second);\n            }\n            for(auto it = st.first;it!=ed.first;it++) {\n                it->second = add + positions[i][1];\n                res = max(res, it->second);\n            }\n            \n            ans.push_back(res);\n        }\n        return ans;\n    }\n};\n```
[]