#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 18) + 10;
int n, m;
long long sum[N], add[N];
int col[N];
bool same[N];
void build(int tl, int tr, int v = 1) {
  if (tl == tr) {
    same[v] = 1;
    col[v] = tl;
    return;
  }
  int tm = (tl + tr) >> 1;
  build(tl, tm, v + v);
  build(tm + 1, tr, v + v + 1);
}
void push(int v, int l, int r) {
  sum[v] += (long long)(r - l + 1) * add[v];
  if (l != r) {
    add[v + v] += add[v];
    add[v + v + 1] += add[v];
    if (same[v]) {
      same[v + v] = same[v + v + 1] = 1;
      col[v + v] = col[v + v + 1] = col[v];
    }
  }
  add[v] = 0;
}
void upd(int l, int r, int c, int v = 1, int tl = 1, int tr = n) {
  push(v, tl, tr);
  if (tr < l || tl > r) return;
  if (l <= tl && tr <= r) {
    if (same[v]) {
      add[v] += abs(col[v] - c);
      col[v] = c;
      push(v, tl, tr);
      return;
    }
    same[v] = 1;
    col[v] = c;
  } else if (same[v] && col[v] != c)
    same[v] = 0, col[v] = 0;
  int tm = (tl + tr) >> 1;
  upd(l, r, c, v + v, tl, tm);
  upd(l, r, c, v + v + 1, tm + 1, tr);
  sum[v] = sum[v + v] + sum[v + v + 1];
}
long long get(int l, int r, int v = 1, int tl = 1, int tr = n) {
  push(v, tl, tr);
  if (tr < l || tl > r) return 0;
  if (l <= tl && tr <= r) return sum[v];
  int tm = (tl + tr) >> 1;
  return get(l, r, v + v, tl, tm) + get(l, r, v + v + 1, tm + 1, tr);
}
int main() {
  scanf("%d%d", &n, &m);
  build(1, n);
  int t, l, r, x;
  while (m--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%d", &l, &r, &x);
      upd(l, r, x);
    } else {
      scanf("%d%d", &l, &r);
      printf("%I64d\n", get(l, r));
    }
  }
  return 0;
}
