#include <bits/stdc++.h>
using namespace std;
int n, m, t, l, r, x, mark[410000];
long long delta[410000], sum[410000];
void read(int &x) {
  char k;
  for (k = getchar(); k <= 32; k = getchar())
    ;
  for (x = 0; '0' <= k; k = getchar()) x = x * 10 + k - '0';
}
void mkt(int k, int q, int h) {
  if (q >= h) {
    mark[k] = q;
    return;
  }
  int ml = (q + h) / 2;
  int mr = ml + 1;
  int kl = k * 2;
  int kr = k * 2 + 1;
  mkt(kl, q, ml);
  mkt(kr, mr, h);
  mark[k] = 0;
}
long long query(int k, int q, int h, int l, int r) {
  if (l <= q && h <= r) return sum[k];
  int ml = (q + h) / 2;
  int mr = ml + 1;
  int kl = k * 2;
  int kr = k * 2 + 1;
  long long d = 1LL * delta[k] * (r - l + 1);
  if (r < mr) return d + query(kl, q, ml, l, r);
  if (ml < l) return d + query(kr, mr, h, l, r);
  return d + query(kl, q, ml, l, ml) + query(kr, mr, h, mr, r);
}
void Clear(int k, int q, int h) {
  if (mark[k] > 0) {
    delta[k] += abs(mark[k] - x);
    sum[k] += 1LL * abs(mark[k] - x) * (h - q + 1);
  } else {
    Clear(k * 2, q, (q + h) / 2);
    Clear(k * 2 + 1, (q + h) / 2 + 1, h);
    sum[k] = sum[k * 2] + sum[k * 2 + 1] + 1LL * delta[k] * (h - q + 1);
  }
  mark[k] = -1;
}
void modify(int k, int q, int h) {
  if (l <= q && h <= r) {
    Clear(k, q, h);
    mark[k] = x;
    return;
  }
  int ml = (q + h) / 2;
  int mr = ml + 1;
  int kl = k * 2;
  int kr = k * 2 + 1;
  if (mark[k] > 0) {
    mark[kl] = mark[kr] = mark[k];
    mark[k] = 0;
  }
  if (r <= ml)
    modify(kl, q, ml);
  else if (ml < l)
    modify(kr, mr, h);
  else {
    modify(kl, q, ml);
    modify(kr, mr, h);
  }
  mark[k] = 0;
  sum[k] = sum[kl] + sum[kr] + 1LL * delta[k] * (h - q + 1);
}
int main() {
  read(n);
  read(m);
  mkt(1, 1, n);
  while (m--) {
    read(t);
    read(l);
    read(r);
    if (t == 1) {
      read(x);
      modify(1, 1, n);
    } else {
      printf("%I64d\n", query(1, 1, n, l, r));
    }
  }
}
