#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

template<class V> class segtree {
private:
    int n;
    vector<V> node, lazy;
    vector<bool> lazyFlag;

public:
    segtree(vector<V> v) {
        int sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1,false);
        rep(i,sz){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[i*2+1],node[i*2+2]);
        }
    }
    void eval(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }
    void range(int a, int b, V x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            eval(k, l, r);
        }
        else {
            range(a, b, x, 2*k+1, l, (l+r)/2);
            range(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }
    V query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a){
            return INT_MAX;
        }
        if(a <= l && r <= b){
            return node[k];
        }
        V vl = query(a, b, 2*k+1, l, (l+r)/2);
        V vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl,vr);
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    segtree<int> sg(vector<int>(n,INT_MAX));
    rep(i,q){
        int k;
        cin >> k;
        if(k){
            int x;
            cin >> x;
            cout << sg.query(x,x+1) << "\n";
        }else{
            int x,y,z;
            cin >> x >> y >> z;
            sg.range(x,y+1,z);
        }
    }
}
#include<cstdio>
#include<algorithm>

using int64=long long;
using uchar=unsigned char;

constexpr int maxn(200000);
constexpr int64 inf(1e17);

template<class _Tp>
	inline bool bchkMin(_Tp&x,const _Tp&y)
		{return(x>y)&&(x=y,1);}

namespace IOManager{
	constexpr int FILESZ(131072);
	char buf[FILESZ];
	const char*ibuf=buf,*tbuf=buf;

	struct IOManager{
		inline char gc()
			{return(ibuf==tbuf)&&(tbuf=(ibuf=buf)+fread(buf,1,FILESZ,stdin),ibuf==tbuf)?EOF:*ibuf++;}

		template<class _Tp>
			inline operator _Tp(){
				_Tp s=0u;char c=gc();
				for(;c<48;c=gc());
				for(;c>47;c=gc())
					s=(_Tp)(s*10u+c-48u);
				return s;
			}
	};
}IOManager::IOManager io;

int sz[maxn+1];
int64 szl[maxn+1],szr[maxn+1];

struct Edge{
	int s,t;int64 w;

	inline void init(const int&is,const int&it,const int64&iw)
		{s=is;t=it;w=iw;}

	inline bool operator<(const Edge&rhs)
		const{return w<rhs.w;}
}e[maxn*30],*cur=e;

void calc(const int&l,const int&r){
	if(l==r)
		return;
	const int m=(l+r)>>1;

	int lmp,rmp;
	int64 lmv=inf,rmv=inf;

	for(int i=l;i<=m;++i)
		if(bchkMin(lmv,szl[i]))
			lmp=i;
	for(int i=m+1;i<=r;++i)
		if(bchkMin(rmv,szr[i]))
			rmp=i;

	for(int i=l;i<=m;++i)
		(++cur)->init(i,rmp,szl[i]+rmv);
	for(int i=m+1;i<=r;++i)
		(++cur)->init(lmp,i,lmv+szr[i]);

	calc(l,m);calc(m+1,r);
}

int ufs[maxn+1];

inline int anc(const int&v)
	{return v==ufs[v]?v:ufs[v]=anc(ufs[v]);}

int main(){
	const int n=io,D=io;
	int64 t=0;
	for(int i=1;i<=n;++i,t+=D)
		ufs[i]=i,
		sz[i]=io,
		szl[i]=sz[i]-t,
		szr[i]=sz[i]+t;

	calc(1,n);
	std::sort(e+1,cur+1);
	int64 ans=0;
	for(Edge*i=e+1;i<=cur;++i)
		if(anc(i->s)!=anc(i->t))
			ans+=i->w,ufs[ufs[i->s]]=ufs[i->t];
	printf("%lld",ans);

	return 0;
}
