#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 1e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
long long seg[maxn * 8];
long long lazy[maxn * 8];
long long nn;
void shift(long long node, long long l, long long r) {
  long long mid = (l + r) / 2;
  seg[2 * node] += lazy[node] * (mid - l);
  seg[2 * node + 1] += lazy[node] * (r - mid);
  lazy[2 * node] += lazy[node];
  lazy[2 * node + 1] += lazy[node];
  lazy[node] = 0;
}
void update1(long long l, long long r, long long node, long long s, long long t,
             long long val) {
  if (s <= l && r <= t) {
    seg[node] += val * (r - l);
    lazy[node] += val;
    return;
  }
  if (r <= s || t <= l) {
    return;
  }
  long long mid = (l + r) / 2;
  shift(node, l, r);
  update1(l, mid, 2 * node, s, t, val);
  update1(mid, r, 2 * node + 1, s, t, val);
  seg[node] = seg[2 * node] + seg[2 * node + 1];
}
void update(long long s, long long t, long long val) {
  update1(0, nn, 1, s, t, val);
}
long long findd(long long l, long long r, long long node, long long s,
                long long t) {
  if (s <= l && r <= t) {
    return seg[node];
  }
  if (r <= s || t <= l) {
    return 0LL;
  }
  long long mid = (l + r) / 2;
  shift(node, l, r);
  return findd(l, mid, 2 * node, s, t) + findd(mid, r, 2 * node + 1, s, t);
}
int main() {
  long long n, m;
  cin >> n >> m;
  nn = n;
  set<pair<long long, pair<long long, long long> > > st;
  for (long long i = 0; i < n; i++) {
    st.insert(make_pair(i, make_pair(i, i + 1)));
  }
  for (long long i = 0; i < m; i++) {
    long long typ;
    cin >> typ;
    if (typ == 1) {
      long long l, r, x;
      cin >> l >> r >> x;
      l--;
      r--;
      set<pair<long long, pair<long long, long long> > >::iterator it;
      it = st.lower_bound(make_pair(l, make_pair(0, 0)));
      if (it != st.begin()) {
        it--;
        if ((*it).first <= l && r <= (*it).second.first) {
          pair<long long, pair<long long, long long> > e = (*it);
          st.erase(it);
          if (e.first <= l - 1) {
            st.insert(make_pair(e.first, make_pair(l - 1, e.second.second)));
          }
          if (l <= r) {
            st.insert(make_pair(l, make_pair(r, x)));
          }
          if (r + 1 <= e.second.first) {
            st.insert(
                make_pair(r + 1, make_pair(e.second.first, e.second.second)));
          }
          update(l, r + 1, abs(e.second.second - x));
          continue;
        }
      }
      it = st.lower_bound(make_pair(l, make_pair(0, 0)));
      while (it != st.end() && (*it).second.first <= r) {
        long long s = (*it).first;
        long long t = (*it).second.first;
        long long xx = (*it).second.second;
        update(s, t + 1, abs(xx - x));
        st.erase(it);
        it = st.lower_bound(make_pair(l, make_pair(0, 0)));
      }
      it = st.lower_bound(make_pair(l, make_pair(0, 0)));
      if (it != st.end()) {
        if ((*it).first <= r) {
          pair<long long, pair<long long, long long> > e = (*it);
          st.erase(it);
          if (r + 1 <= e.second.first) {
            st.insert(make_pair(r + 1, e.second));
          }
          update(e.first, r + 1, abs(e.second.second - x));
        }
      }
      it = st.lower_bound(make_pair(l, make_pair(0, 0)));
      if (it != st.begin()) {
        it--;
        if (l <= (*it).second.first) {
          pair<long long, pair<long long, long long> > e = (*it);
          st.erase(it);
          if (e.first <= l - 1) {
            st.insert(make_pair(e.first, make_pair(l - 1, e.second.second)));
          }
          update(l, e.second.first + 1, abs(e.second.second - x));
        }
      }
      st.insert(make_pair(l, make_pair(r, x)));
    } else {
      long long l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << findd(0, n, 1, l, r + 1) << endl;
    }
  }
}
