#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, N = 100010, MAX = 320;
const long long INFL = 1e18;
int n, m, nBlock, S;
int a[N], v[MAX][MAX], sz[MAX];
long long sum[MAX], lazy[MAX], add[MAX], ans[N], f[MAX][MAX];
void lazy_upd(int b) {
  if (lazy[b] != -1) {
    for (int i = b * S; i <= (b + 1) * S - 1; i++)
      ans[i] += add[b], a[i] = lazy[b];
    sum[b] += add[b] * sz[b];
    add[b] = 0;
    lazy[b] = -1;
  }
}
void block_upd(int l, int r, int x) {
  int b = l / S;
  lazy_upd(b);
  for (int i = l; i <= r; i++)
    ans[i] += abs(x - a[i]), sum[b] += abs(x - a[i]), a[i] = x;
}
void range_upd(int l, int r, int x) {
  for (int b = l; b <= r; b++) {
    if (lazy[b] != -1)
      add[b] += abs(x - lazy[b]), lazy[b] = x;
    else {
      for (int i = b * S; i <= (b + 1) * S - 1; i++) {
        ans[i] += abs(x - a[i]);
        sum[b] += abs(x - a[i]);
        add[b] = 0;
        lazy[b] = x;
        a[i] = x;
      }
    }
  }
}
long long range_get(int l, int r) {
  long long res = 0;
  for (int b = l; b <= r; b++) {
    if (lazy[b] != -1)
      res += sum[b] + add[b] * sz[b];
    else
      res += sum[b];
  }
  return res;
}
long long block_get(int l, int r) {
  long long res = 0;
  int b = l / S;
  lazy_upd(b);
  for (int i = l; i <= r; i++) res += ans[i];
  return res;
}
void updQuery(int l, int r, int x) {
  int L = l / S, R = r / S;
  if (L == R) {
    block_upd(l, r, x);
  } else {
    if (l % S != 0) L++;
    if (r % S != S - 1) R--;
    range_upd(L, R, x);
    block_upd(l, L * S - 1, x);
    block_upd((R + 1) * S, r, x);
  }
}
long long getQuery(int l, int r) {
  int L = l / S, R = r / S;
  long long res = 0;
  if (L == R) {
    res += block_get(l, r);
  } else {
    if (l % S != 0) L++;
    if (r % S != S - 1) R--;
    res += range_get(L, R);
    res += block_get(l, L * S - 1);
    res += block_get((R + 1) * S, r);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  S = MAX - 1;
  for (int i = 0; i <= n - 1; i++) a[i] = i + 1;
  for (int i = 0; i <= n - 1; i++) {
    sz[i / S]++;
    lazy[i / S] = -1;
  }
  while (m--) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      r--;
      updQuery(l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      printf("%I64d\n", getQuery(l, r));
    }
  }
}
