Easy Soln || Clean Code || Simple Approach
IntuitionSimple observation is that when we are placing a block at any postion p , only two gaps change, one between the current node and after node(if exists),
# Intuition
Simple observation is that when we are placing a block at any postion p , *only two gaps change*, one between the current node and after node(if exists), and other between the current node and before node (we assume 0 as dummy node).

# Approach
- So we just store the postions where we are going to place the block and sort them. 
- Also we maintain a map "**index**" to store the indices of this position which will be used further in segment tree queries.
- We also maintain a set "**st**" that contains the current positions where blocks have been placed(insert 0 as dummy position), this set will help us to find whether there is any block which is placed previously and postion of that block is after this block.
- Also we will be having an array "**a**", that will store the consecutive gaps, between blocks.
- Also we will be using one segment tree "**tree**" to find max gap upto index "i" in logarithmic time.
- Now when we iterating over queries-
1. Type - 1
Using set "**st**" we can find whether any block after this exists or not.If yes then we update gaps of both current and after block postions, otherwise gap of current block is updated.(Indices of block can be accessed by using map "**index**")
Also these updates are performed in segment tree "**tree**".
2. Type - 2
We find the postion "**p**" which is just before "x" (the position upto which we can place block), and using segment trees we can find max gap upto index "**i**" of before postion (*i = index[p]*), if any distance remain between before node "**p**" and "**x**" we take max of them. 
If this max value is less than block size then not possible to place block, otherwise we can place the block.


# Complexity
- Time complexity:
**T.C - O(n*log(n))**, since for each query we are querying for max element or performing set operations.

- Space complexity:
To store segment tree.
**S.C - O(4*n)**

# Code
```cpp []
class Solution {
public:
    void buildTree(int *tree,int *a,int index,int s,int e)
    {
        if(s>e)
            return;
        if(s==e)
        {
            tree[index]=a[s];
            return ;
        }
        int m = (s+e)/2;
        buildTree(tree,a,2*index,s,m);
        buildTree(tree,a,2*index+1,m+1,e);
        tree[index]= max(tree[2*index],tree[2*index+1]);
        return;
    }

    int query(int *tree,int index,int s,int e,int qs,int qe)
    {
        if(qs>e || s>qe)
            return INT_MIN;
        if(s>=qs && e<=qe)
            return tree[index];
        int m = (s+e)/2;
        int left_ans = query(tree,2*index,s,m,qs,qe);
        int right_ans = query(tree,2*index+1,m+1,e,qs,qe);
        return max(left_ans,right_ans);
    }
    void updateNode(int *tree,int index,int s,int e,int pos,int val)
    {
        if(pos<s || pos>e)
            return ;
        if(s==e)
        {
            tree[index] = val;
            return ;
        }
        int m = (s+e)/2;
        updateNode(tree,2*index,s,m,pos,val);
        updateNode(tree,2*index+1,m+1,e,pos,val);
        tree[index] = max(tree[2*index],tree[2*index+1]);
        return;
    }
public:
    vector<bool> getResults(vector<vector<int>>& queries) {
        vector<bool> ans;
        vector<int> positions;
        for(auto &it : queries){
            if(it[0] == 1){
                positions.push_back(it[1]);
            }
        }
        sort(positions.begin(),positions.end());
        map<int,int> index;
        int idx = 1;
        for(auto &it : positions)index[it] = idx++;

        int sz = index.size();
        sz += 1;
        //array to store consecutive gaps between positions
        int a[sz];
        for(int i=0;i<sz;i++)a[i] = 0; 
        int *tree = new int[4*sz+1]; 
        int indexx = 1;									
        int s = 0,e = sz-1;
        buildTree(tree,a,indexx,s,e); 	

        set<int> st; //will store the current positions of query 1
        st.insert(0);
        for(auto &it : queries){
            if(it[0] == 1){
                int p = it[1];
                int j = index[p];
                auto it = st.upper_bound(p);
                if(it != st.end()){
                    //gap of node after p will also change
                    auto ec = it;
                    int p2 = *ec;
                    int j2 = index[p2];
                    a[j2] = p2-p;
                    updateNode(tree,indexx,s,e,j2,a[j2]);
                }
                //gap of this node will change
                auto ec = it;
                --ec;
                int p0 = *ec;
                int j0 = index[p0];
                a[j] = p-p0;
                updateNode(tree,indexx,s,e,j,a[j]);
                st.insert(p);
            }
            else{
                int p = it[1],block_size = it[2];
                auto it = st.upper_bound(p);
                --it;
                int p2 = *it;
                int j2 = index[p2];
                int mx = query(tree,indexx,s,e,0,j2);
                mx = max(mx,p-p2);
                bool flag = false;
                if(block_size <= mx){
                    flag = true;
                }
                ans.push_back(flag);
            }
        }
        return ans;
    }
};
```
['Array', 'Segment Tree', 'C++']