#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
long long n, m, S;
long long a[N], sz[N], lazy[N], ans[N], cong[N], tong[N];
void lazyup(long long b) {
  if (lazy[b] != -1) {
    for (long long i = b * S; i <= (b + 1) * S - 1; i++) {
      a[i] = lazy[b];
      ans[i] += cong[b];
      tong[b] += cong[b];
    }
    cong[b] = 0;
    lazy[b] = -1;
  }
}
void upVal(long long l, long long r, long long x) {
  long long b = l / S;
  lazyup(b);
  for (long long i = l; i <= r; i++) {
    ans[i] += abs(a[i] - x);
    tong[b] += abs(a[i] - x);
    a[i] = x;
  }
}
void upBlock(long long l, long long r, long long x) {
  for (long long b = l; b <= r; b++) {
    if (lazy[b] != -1) {
      cong[b] += abs(lazy[b] - x);
      lazy[b] = x;
    } else {
      lazy[b] = x;
      for (long long i = b * S; i <= (b + 1) * S - 1; i++) {
        ans[i] += abs(a[i] - x);
        tong[b] += abs(a[i] - x);
        a[i] = x;
      }
      cong[b] = 0;
    }
  }
}
void upQuery(long long l, long long r, long long x) {
  long long L = l / S, R = r / S;
  if (L == R)
    upVal(l, r, x);
  else {
    if (l % S != 0) L++;
    if (r % S != (S - 1)) R--;
    upBlock(L, R, x);
    upVal(l, L * S - 1, x);
    upVal((R + 1) * S, r, x);
  }
}
long long getBlock(long long l, long long r) {
  long long res = 0;
  for (long long b = l; b <= r; b++) {
    if (lazy[b] != -1)
      res += tong[b] + cong[b] * sz[b];
    else
      res += tong[b];
  }
  return res;
}
long long getVal(long long l, long long r) {
  long long b = l / S, res = 0;
  lazyup(b);
  for (long long i = l; i <= r; i++) res += ans[i];
  return res;
}
long long dapan(long long l, long long r) {
  long long L = l / S, R = r / S, res = 0;
  if (L == R)
    res += getVal(l, r);
  else {
    if (l % S != 0) L++;
    if (r % S != (S - 1)) R--;
    res += getBlock(L, R);
    res += getVal(l, L * S - 1);
    res += getVal((R + 1) * S, r);
  }
  return res;
}
signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  cin >> n >> m;
  S = sqrt(n) + 1;
  for (long long i = 0; i < n; i++) a[i] = i + 1, sz[i / S]++, lazy[i / S] = -1;
  while (m--) {
    long long type, l, r, x;
    cin >> type >> l >> r;
    l--;
    r--;
    if (type == 1) {
      cin >> x;
      upQuery(l, r, x);
    } else {
      cout << dapan(l, r) << "\n";
    }
  }
}
