#include <bits/stdc++.h>
using namespace std;
long long sum[100005 << 2], col[100005 << 2], add[100005 << 2];
void build(int l, int r, int rt) {
  sum[rt] = 0;
  col[rt] = 0;
  add[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);
}
void pushdown(int l, int r, int rt) {
  if (add[rt]) {
    int m = (l + r) >> 1;
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    sum[rt << 1] += (m - l + 1) * add[rt];
    sum[rt << 1 | 1] += (r - m) * add[rt];
    add[rt] = 0;
    if (col[rt] != 0) {
      col[rt << 1] = col[rt];
      col[rt << 1 | 1] = col[rt];
    }
  }
}
void pushup(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  if (col[rt << 1] == col[rt << 1 | 1] && col[rt << 1] != 0)
    col[rt] = col[rt << 1];
  else
    col[rt] = 0;
}
void update(int L, int R, long long val, int l, int r, int rt) {
  if (L <= l && R >= r && col[rt] != 0) {
    add[rt] += abs(val - col[rt]);
    sum[rt] += (long long)(r - l + 1) * abs(val - col[rt]);
    col[rt] = val;
    return;
  }
  int m = (l + r) >> 1;
  pushdown(l, r, rt);
  if (L <= m) update(L, R, val, l, m, rt << 1);
  if (R > m) update(L, R, val, 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(l, r, rt);
  long long ans = 0;
  if (L <= m) ans += query(L, R, l, m, rt << 1);
  if (R > m) ans += query(L, R, m + 1, r, rt << 1 | 1);
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  long long x, y, z, a;
  while (m--) {
    scanf("%I64d", &a);
    if (a == 1) {
      scanf("%I64d%I64d%I64d", &x, &y, &z);
      update(x, y, z, 1, n, 1);
    } else {
      scanf("%I64d%I64d", &x, &y);
      printf("%I64d\n", query(x, y, 1, n, 1));
    }
  }
  return 0;
}
