#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, sn, m, i, i2, i3, tmp, l, r, x, a[101001], b[101001], ta[401],
    sumb[401], tb[401], ans, th, tl, tr;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m, sn = sqrt(n);
  for (i = 0; i < n; i++) a[i] = i + 1;
  while (m--) {
    cin >> tmp >> l >> r, l--, r--;
    if (tmp == 1) {
      cin >> x;
      for (i = l; i <= r;) {
        th = i / sn, tl = th * sn, tr = min(tl + sn, n);
        if (i == tl && r >= tr - 1) {
          if (ta[th])
            tb[th] += abs(ta[th] - x), sumb[th] += abs(ta[th] - x) * (tr - tl);
          else
            for (i2 = tl; i2 < tr; i2++)
              b[i2] += abs(a[i2] - x), sumb[th] += abs(a[i2] - x);
          ta[th] = x, i = tr;
        } else {
          if (ta[th]) {
            for (i2 = tl; i2 < tr; i2++) a[i2] = ta[th];
            ta[th] = 0;
          }
          b[i] += abs(a[i] - x), sumb[th] += abs(a[i] - x), a[i] = x, i++;
        }
      }
    } else {
      ans = 0;
      for (i = l; i <= r;) {
        tl = i / sn * sn, tr = min(tl + sn, n), th = i / sn;
        if (i == tl && r >= tr - 1)
          ans += sumb[th], i = tr;
        else
          ans += tb[th] + b[i], i++;
      }
      cout << ans << '\n';
    }
  }
}
