#include <bits/stdc++.h>
using namespace std;
long long n, m, t, l, r, tam, a[100010], x, bloco[1000], clf[100010],
    bclf[1000], bclft[1000];
int main() {
  scanf("%lld %lld", &n, &m);
  for (long long i = 0; i < n; i++) a[i] = i + 1;
  tam = sqrt(n);
  for (long long i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &t, &l, &r);
    l--;
    if (t == 1) {
      scanf("%lld", &x);
      while (l < r) {
        if (l % tam || (r - l < tam && r < n)) {
          if (bloco[l / tam]) {
            for (long long j = l - (l % tam); j < l - (l % tam) + tam && j < n;
                 j++)
              a[j] = bloco[l / tam];
            bloco[l / tam] = 0;
          }
          clf[l] += abs(x - a[l]);
          bclft[l / tam] += abs(x - a[l]);
          a[l] = x;
          l++;
        } else {
          if (bloco[l / tam]) {
            bclf[l / tam] += abs(x - bloco[l / tam]);
            bclft[l / tam] += min(tam, r - l) * abs(x - bloco[l / tam]);
          } else {
            for (long long j = l; j < r && j < l + tam; j++) {
              bclft[l / tam] += abs(x - a[j]);
              clf[j] += abs(x - a[j]);
            }
          }
          bloco[l / tam] = x;
          l += tam;
        }
      }
    } else {
      long long resp = 0;
      while (l < r) {
        if (l % tam || (r - l < tam && r < n)) {
          while ((l % tam || r - l < tam) && l < r) {
            resp += bclf[l / tam] + clf[l];
            l++;
          }
        } else {
          resp += bclft[l / tam];
          l += tam;
        }
      }
      printf("%lld\n", resp);
    }
  }
  return 0;
}
