Lazy Segment tree || with index 1
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ --> \n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ --> \n\n# Code\n```\nclass Solution {\npublic:\n    const static int N = 1e5 + 2;\n    int INF = 1e9;\n    int tree[4 * N], lazy[4 * N], a[4*N];\n\n    void build(int v, int tl, int tr) {\n        if (tl == tr) {\n            tree[v] = a[tl];\n        } else {\n            int tm = (tl + tr) / 2;\n            build(v*2+1, tl, tm);\n            build(v*2+2, tm+1, tr);\n            tree[v] = max(tree[v*2+1], tree[v*2 + 2]);\n        }\n    }\n\n\n    void push(int node){\n        if(lazy[node]!=-1){\n            tree[2*node] = lazy[node];\n            tree[2*node+1] = lazy[node];\n\n            lazy[2*node] = lazy[node];\n            lazy[2*node+1] = lazy[node];\n            lazy[node] = -1;\n        }\n    }\n\n    void update(int node, int tl, int tr, int l, int r, int updatedVal){\n        if (tl > tr)return;\n        else if (l<=tl && tr <=r){\n            tree[node] = updatedVal;\n            lazy[node] = updatedVal; // ye value update krni hai tl to tr segment of segment tree.\n        }\n        else if(tl==tr && (tl<l||tr>r)) return;\n        else{\n            push(node);\n            int tm = (tl + tr) / 2;\n            update(2*node, tl, tm, l,r, updatedVal);\n            update(2*node + 1, tm + 1, tr,l, r, updatedVal);\n            tree[node] = max(tree[2*node], tree[2*node+ 1]);\n        }\n    }\n\n\n    int query(int node, int tl, int tr, int l, int r){\n        if (tl >tr) return -INF;\n        if (l <= tl && tr <= r) return tree[node];\n        if(tl==tr) return -INF;\n\n        push(node);\n        int tm = (tl + tr) / 2;\n        int q1=query(2*node, tl, tm, l,r);\n        int q2=query(2*node + 1, tm + 1, tr,l, r);\n        return max(q1,q2);\n    }\n\n\n    vector<int> fallingSquares(vector<vector<int>>& pos) {\n        memset(tree,0,sizeof(tree));\n        memset(lazy,0,sizeof(lazy));\n        memset(a,0,sizeof(a));\n\n        \n\n\n        unordered_map<int,int> mp;\n        set<int> st;\n        for(auto x : pos){\n            st.insert(x[0]);\n            st.insert(x[0]+x[1]-1);\n        }\n\n        int idx = 1;\n        for(auto x : st){\n            mp[x] = idx;\n            idx++;\n        }\n\n        int n = idx;\n        build(1, 1, n);\n        vector<int> ans;\n        for(auto x : pos){\n            int l = mp[x[0]];\n            int r = mp[x[0]+x[1]-1];\n\n            int mxi = query(1, 1, n, l, r);\n            update(1, 1, n, l, r, mxi+x[1]);\n\n            int temp = query(1,1,n,1,n);\n            ans.push_back(temp);\n        }\n\n\n        return ans;\n    }\n};\n```
['C++']