#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5;
const long long SQ = 330;
long long a[MAX], t[MAX], cur[MAX];
long long n, queries, col[SQ];
long long sc[SQ], sum[SQ];
vector<long long> v[SQ];
void update(long long x, long long y, long long block, long long c,
            long long q) {
  long long l = SQ * block, r = min(n, (block + 1) * SQ);
  if (r <= l) return;
  if (x <= l && r <= y) {
    long long per = col[block];
    col[block] = c;
    sc[block] += abs(per - c);
    for (auto i : v[block]) {
      long long p = t[i];
      long long z = abs(a[i] - c);
      t[i] -= abs(c - per);
      t[i] += z;
      a[i] = c;
      sum[block] += t[i] - p;
    }
    v[block].clear();
    return;
  }
  l = max(l, x);
  r = min(r, y);
  if (r - l < 1) return;
  for (auto i : v[block]) cur[i] = q;
  for (long long i = l; i < r; i++) {
    long long val;
    if (cur[i] == q)
      val = a[i];
    else
      val = col[block], v[block].push_back(i);
    long long d = abs(val - c);
    a[i] = c;
    t[i] += d;
    sum[block] += d;
  }
}
long long ret = 0;
void ans(long long x, long long y, long long block) {
  long long l = SQ * block, r = min(n, (block + 1) * SQ);
  if (r <= l) return;
  if (x <= l && r <= y) {
    ret += sc[block] * (r - l) + sum[block];
    return;
  }
  l = max(l, x);
  r = min(r, y);
  if (r - l < 1) return;
  ret += sc[block] * (r - l);
  for (long long i = l; i < r; i++) ret += t[i];
}
int main() {
  long long q;
  cin >> n >> q;
  for (long long i = 0; i < n; i++) a[i] = i + 1, v[i / SQ].push_back(i);
  while (q--) {
    long long ty, l, r;
    scanf("%I64d", &ty);
    scanf("%I64d", &l);
    scanf("%I64d", &r);
    if (ty == 2) {
      ret = 0;
      for (long long i = 0; i < SQ + 2; i++) ans(l - 1, r, i);
      cout << ret << endl;
      continue;
    }
    long long c;
    scanf("%I64d", &c);
    for (long long i = 0; i < SQ + 2; i++) update(l - 1, r, i, c, q);
  }
  return 0;
}
