#include <bits/stdc++.h>
using namespace std;
int col[111111 << 2];
long long sum[111111 << 2];
long long val[111111 << 2];
void PushUp(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  if (col[rt << 1] == col[rt << 1 | 1])
    col[rt] = col[rt << 1];
  else
    col[rt] = 0;
}
void PushDown(int rt, int l, int r) {
  int m = (l + r) >> 1;
  if (val[rt]) {
    sum[rt << 1] += val[rt] * (m - l + 1);
    sum[rt << 1 | 1] += val[rt] * (r - m);
    val[rt << 1] += val[rt];
    val[rt << 1 | 1] += val[rt];
    col[rt << 1] = col[rt << 1 | 1] = col[rt];
    col[rt] = 0;
    val[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  col[rt] = 0;
  sum[rt] = 0;
  val[rt] = 0;
  if (l == r) {
    col[rt] = l;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  PushUp(rt);
}
void update(int L, int R, int c, int l, int r, int rt) {
  if (L <= l && r <= R && col[rt]) {
    val[rt] += fabs(col[rt] - c);
    sum[rt] += fabs(col[rt] - c) * (r - l + 1);
    col[rt] = c;
    return;
  }
  PushDown(rt, l, r);
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, c, l, m, rt << 1);
  if (R > m) update(L, R, c, m + 1, r, rt << 1 | 1);
  PushUp(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return sum[rt];
  int m = (l + r) >> 1;
  PushDown(rt, l, r);
  long long res = 0;
  if (L <= m) res += query(L, R, l, m, rt << 1);
  if (R > m) res += query(L, R, m + 1, r, rt << 1 | 1);
  PushUp(rt);
  return res;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  while (m--) {
    int a, b, c, d;
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d%d%d", &b, &c, &d);
      update(b, c, d, 1, n, 1);
    } else {
      scanf("%d%d", &b, &c);
      printf("%I64d\n", query(b, c, 1, n, 1));
    }
  }
  return 0;
}
