#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 1e5 + 9;
long long arr[N], sum[N], sumall[N], color[N], val[N];
int main() {
  file();
  fast();
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) arr[i] = i + 1;
  int sq = sqrt(n);
  while (q--) {
    int t, l, r;
    cin >> t >> l >> r;
    l--, r--;
    if (t == 1) {
      int x;
      cin >> x;
      for (int j = l; j <= r; j++) {
        if (j % sq == 0 && j + sq - 1 <= r) {
          if (color[j / sq])
            sum[j / sq] += abs(x - color[j / sq]),
                sumall[j / sq] += abs(x - color[j / sq]) * sq;
          else
            for (int tmp = j; tmp <= j + sq - 1; tmp++)
              val[tmp] += abs(arr[tmp] - x),
                  sumall[j / sq] += abs(arr[tmp] - x);
          color[j / sq] = x;
          j += sq - 1;
        } else {
          if (color[j / sq]) {
            int tmp = (j / sq) * sq;
            while (tmp / sq == j / sq) arr[tmp++] = color[j / sq];
            color[j / sq] = 0;
          }
          val[j] += abs(arr[j] - x), sumall[j / sq] += abs(arr[j] - x),
              arr[j] = x;
        }
      }
    } else {
      long long ans = 0;
      for (int j = l; j <= r; j++) {
        if (j % sq == 0 && j + sq - 1 <= r)
          ans += sumall[j / sq], j += sq - 1;
        else
          ans += val[j] + sum[j / sq];
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
