#include <bits/stdc++.h>
using namespace std;
long long sum[400009], add[400009];
int co[400009];
void pushup(int p, int l, int r) {
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
  if (co[p << 1] == co[p << 1 | 1])
    co[p] = co[p << 1];
  else
    co[p] = 0;
}
void pushdown(int p, int l, int r) {
  if (add[p]) {
    add[p << 1] += add[p];
    add[p << 1 | 1] += add[p];
    int mid = (l + r) >> 1;
    sum[p << 1] += (long long)(mid - l + 1) * add[p];
    sum[p << 1 | 1] += (long long)(r - mid) * add[p];
    co[p << 1] = co[p << 1 | 1] = co[p];
    add[p] = 0;
  }
}
void build(int p, int l, int r) {
  if (l == r) {
    add[p] = sum[p] = 0;
    co[p] = l;
    return;
  }
  int mid = (l + r) >> 1;
  add[p] = 0;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p, l, r);
}
void update(int p, int l, int r, int ql, int qr, int d) {
  if (ql <= l && qr >= r && co[p]) {
    sum[p] += (long long)(r - l + 1) * abs(d - co[p]);
    add[p] += abs(d - co[p]);
    co[p] = d;
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(p << 1, l, mid, ql, qr, d);
  if (qr > mid) update(p << 1 | 1, mid + 1, r, ql, qr, d);
  pushup(p, l, r);
}
long long query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && qr >= r) return sum[p];
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  long long ans = 0;
  if (ql <= mid) ans += query(p << 1, l, mid, ql, qr);
  if (qr > mid) ans += query(p << 1 | 1, mid + 1, r, ql, qr);
  pushup(p, l, r);
  return ans;
}
int main() {
  int n, i, j, k, m, ii = 0, ca;
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  while (m--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int l, r, d;
      scanf("%d%d%d", &l, &r, &d);
      update(1, 1, n, l, r, d);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      cout << query(1, 1, n, l, r) << endl;
    }
  }
  return 0;
}
