#include <bits/stdc++.h>
using namespace std;
long long color[100005 << 2];
long long sum[100005 << 2];
long long delta[100005 << 2];
int n, m, ql, qr, x;
long long ans;
void build(int o, int L, int R) {
  if (L == R) {
    sum[o] = delta[o] = 0;
    color[o] = L;
    return;
  }
  color[o] = 0;
  int mid = (L + R) >> 1;
  build(o << 1, L, mid);
  build(o << 1 | 1, mid + 1, R);
}
void pushup(int o, int L, int R) {
  if (color[o << 1] == color[o << 1 | 1])
    color[o] = color[o << 1];
  else
    color[o] = 0;
  sum[o] = sum[o << 1] + sum[o << 1 | 1];
}
void pushdown(int o, int L, int R) {
  if (!color[o]) return;
  int mid = (R + L) >> 1;
  delta[o << 1] += delta[o];
  delta[o << 1 | 1] += delta[o];
  sum[o << 1] += delta[o] * (mid - L + 1);
  sum[o << 1 | 1] += delta[o] * (R - mid);
  color[o << 1] = color[o << 1 | 1] = color[o];
  delta[o] = color[o] = 0;
}
void updata(int o, int L, int R) {
  if (ql <= L && qr >= R && color[o]) {
    delta[o] += abs(color[o] - x);
    sum[o] += abs(color[o] - x) * (R - L + 1);
    color[o] = x;
    return;
  }
  pushdown(o, L, R);
  int mid = (L + R) >> 1;
  if (ql <= mid) updata(o << 1, L, mid);
  if (qr > mid) updata(o << 1 | 1, mid + 1, R);
  pushup(o, L, R);
}
void query(int o, int L, int R) {
  if (ql <= L && qr >= R) {
    ans += sum[o];
    return;
  }
  pushdown(o, L, R);
  int mid = (L + R) >> 1;
  if (ql <= mid) query(o << 1, L, mid);
  if (qr > mid) query(o << 1 | 1, mid + 1, R);
  pushup(o, L, R);
}
void debug(void) { printf("%I64d %I64d\n", sum[4], sum[5]); }
void solve(void) {
  int k;
  while (m--) {
    scanf("%d", &k);
    if (k == 1) {
      scanf("%d%d%d", &ql, &qr, &x);
      updata(1, 1, n);
    } else {
      scanf("%d%d", &ql, &qr);
      ans = 0;
      query(1, 1, n);
      printf("%I64d\n", ans);
    }
  }
}
int main(void) {
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  solve();
  return 0;
}
