#include <bits/stdc++.h>
using namespace std;
long long N, Q, op, l, r, col, cnt;
long long tree[100100 * 4], xtra[100100 * 4], v;
int b[100100 * 4], e[100100 * 4];
void init(int n, int beg, int end) {
  b[n] = beg;
  e[n] = end;
  if (beg == end) return;
  int m = beg + (end - beg) / 2;
  init(2 * n, beg, m);
  init(2 * n + 1, m + 1, end);
}
void push(int n) {
  xtra[2 * n] += xtra[n];
  tree[2 * n] += (e[2 * n] - b[2 * n] + 1) * xtra[n];
  xtra[2 * n + 1] += xtra[n];
  tree[2 * n + 1] += (e[2 * n + 1] - b[2 * n + 1] + 1) * xtra[n];
  xtra[n] = 0;
}
void update(int n) {
  if (b[n] > r || e[n] < l) return;
  if (b[n] >= l && e[n] <= r) {
    xtra[n] += v;
    tree[n] += (e[n] - b[n] + 1) * v;
    return;
  }
  push(n);
  update(2 * n);
  update(2 * n + 1);
  tree[n] = tree[2 * n] + tree[2 * n + 1];
}
long long query(int n) {
  if (b[n] > r || e[n] < l) return 0;
  if (b[n] >= l && e[n] <= r) return tree[n];
  push(n);
  return query(2 * n) + query(2 * n + 1);
}
struct iv {
  long long l, r;
  long long col;
  iv() {}
  iv(long long _l, long long _r, long long _col) {
    l = _l;
    r = _r;
    col = _col;
  }
  bool operator<(iv o) const { return l < o.l; }
} curr[100100];
set<iv> S;
set<iv>::iterator lo, hi, it;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> Q;
  for (long long I = 1; I <= N; I++) S.insert(iv(I, I, I));
  init(1, 1, N);
  while (Q--) {
    cin >> op >> l >> r;
    if (op == 1) {
      cin >> col;
      lo = S.upper_bound(iv(l, 0, 0));
      hi = S.upper_bound(iv(r, 0, 0));
      lo--;
      cnt = 0;
      for (it = lo; it != hi; it++) curr[cnt++] = *it;
      S.erase(lo, hi);
      if (curr[0].l < l) {
        S.insert(iv(curr[0].l, l - 1, curr[0].col));
        curr[0].l = l;
      }
      if (curr[cnt - 1].r > r) {
        S.insert(iv(r + 1, curr[cnt - 1].r, curr[cnt - 1].col));
        curr[cnt - 1].r = r;
      }
      S.insert(iv(l, r, col));
      for (long long I = 0; I < cnt; I++) {
        l = curr[I].l;
        r = curr[I].r;
        v = abs(curr[I].col - col);
        update(1);
      }
    } else if (op == 2) {
      cout << query(1) << "\n";
    } else
      assert(false);
  }
}
