#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int block, l[N], r[N];
int belong[N];
int num;
long long a[N];
int n, m;
long long b[N];
long long ls[N], lz[N];
long long extra[N];
void build() {
  block = sqrt(n);
  num = n / block;
  if (n % block) num++;
  for (int i = 1; i <= num; i++) {
    l[i] = (i - 1) * block + 1;
    r[i] = i * block;
  }
  r[num] = n;
  for (int i = 1; i <= n; i++) {
    belong[i] = (i - 1) / block + 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  build();
  for (int i = 1; i <= n; i++) a[i] = i;
  while (m--) {
    int cmd;
    int L, R;
    long long w;
    scanf("%d", &cmd);
    if (cmd == 1) {
      scanf("%d%d%I64d", &L, &R, &w);
      for (int i = L; i <= R;) {
        int k = belong[i];
        int y = min(R, r[k]);
        if (i == l[k] && y == r[k]) {
          if (!ls[k]) {
            for (int o = l[k]; o <= r[k]; o++) {
              b[o] += (long long)fabs(a[o] - w);
              extra[k] += (long long)fabs(a[o] - w);
              a[o] = w;
            }
            ls[k] = w;
          } else {
            extra[k] += (r[k] - l[k] + 1) * ((long long)fabs(ls[k] - w));
            lz[k] += (long long)fabs(ls[k] - w);
            ls[k] = w;
          }
          i = r[k] + 1;
        } else {
          if (ls[k]) {
            for (int o = l[k]; o <= r[k]; o++) {
              a[o] = ls[k];
            }
            ls[k] = 0;
          }
          b[i] += (long long)fabs(a[i] - w);
          extra[k] += (long long)fabs(a[i] - w);
          a[i] = w;
          i++;
        }
      }
    } else {
      scanf("%d%d", &L, &R);
      long long sum = 0;
      for (int i = L; i <= R;) {
        int k;
        k = belong[i];
        int y = min(R, r[k]);
        if (i == l[k] && y == r[k]) {
          sum += extra[k];
          i = r[k] + 1;
        } else {
          sum += b[i] + lz[k];
          i++;
        }
      }
      printf("%I64d\n", sum);
    }
  }
}
