#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 2e18;
const long long K = 400;
const long long len = 450;
long long n;
long long a[maxn], c[K];
long long cnt[K];
bool is[K];
long long tl[K], tr[K];
long long Fh[maxn], Fbh[K];
void shift(long long v) {
  if (is[v])
    for (long long i = tl[v]; i <= tr[v]; i++) {
      Fh[i] += Fbh[v];
      a[i] = c[v];
    }
  c[v] = 0;
  Fbh[v] = 0;
  is[v] = 0;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) {
    if (i != n)
      if ((i / len) != ((i + 1) / len)) {
        tl[(i + 1) / len] = i + 1;
        tr[i / len] = i;
      }
    a[i] = i;
  }
  tl[0] = 1;
  tr[n / len] = n;
  while (q--) {
    long long tp;
    cin >> tp;
    if (tp == 1) {
      long long l, r, C;
      cin >> l >> r >> C;
      long long x = l / len;
      long long y = r / len;
      if (x == y) {
        shift(x);
        for (long long i = l; i <= r; i++) {
          cnt[x] += abs(C - a[i]);
          Fh[i] += abs(C - a[i]);
          a[i] = C;
        }
        continue;
      }
      shift(x);
      shift(y);
      for (long long i = l; i <= tr[x]; i++) {
        cnt[x] += abs(C - a[i]);
        Fh[i] += abs(C - a[i]);
        a[i] = C;
      }
      for (long long i = tl[y]; i <= r; i++) {
        cnt[y] += abs(C - a[i]);
        Fh[i] += abs(C - a[i]);
        a[i] = C;
      }
      for (long long i = x + 1; i < y; i++)
        if (is[i]) {
          cnt[i] += (tr[i] - tl[i] + 1) * (abs(C - c[i]));
          Fbh[i] += abs(C - c[i]);
          c[i] = C;
        } else {
          for (long long j = tl[i]; j <= tr[i]; j++) {
            cnt[i] += abs(a[j] - C);
            Fh[j] += abs(a[j] - C);
          }
          c[i] = C;
          is[i] = 1;
        }
    } else {
      long long l, r;
      cin >> l >> r;
      long long ans = 0;
      long long x = l / len, y = r / len;
      if (x == y) {
        for (long long i = l; i <= r; i++) ans += Fh[i] + Fbh[x];
        cout << ans << "\n";
        continue;
      }
      for (long long i = x + 1; i < y; i++) ans += cnt[i];
      for (long long i = l; i <= tr[x]; i++) ans += Fh[i] + Fbh[x];
      for (long long i = tl[y]; i <= r; i++) ans += Fh[i] + Fbh[y];
      cout << ans << "\n";
    }
  }
}
