#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 7;
int n, q;
int col[MX << 2];
long long sum[MX << 2], add[MX << 2];
void push_up(int rt) {
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  if (col[rt << 1] && col[rt << 1] == col[rt << 1 | 1])
    col[rt] = col[rt << 1];
  else
    col[rt] = 0;
}
void push_down(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] += (long long)(m - l + 1) * add[rt];
    sum[rt << 1 | 1] += (long long)(r - m) * add[rt];
    col[rt << 1] = col[rt << 1 | 1] = col[rt];
    add[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  sum[rt] = 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);
  push_up(rt);
}
void update(int L, int R, int x, int l, int r, int rt) {
  if (L <= l && r <= R && col[rt]) {
    sum[rt] += (long long)(r - l + 1) * abs(x - col[rt]);
    add[rt] += abs(x - col[rt]);
    col[rt] = x;
    return;
  }
  push_down(l, r, rt);
  int m = (l + r) >> 1;
  if (L <= m) update(L, R, x, l, m, rt << 1);
  if (R > m) update(L, R, x, m + 1, r, rt << 1 | 1);
  push_up(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) return sum[rt];
  push_down(l, r, rt);
  int m = (l + r) >> 1;
  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);
  return res;
}
int main() {
  scanf("%d%d", &n, &q);
  build(1, n, 1);
  int op, l, r, x;
  while (q--) {
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &x);
      update(l, r, x, 1, n, 1);
    } else {
      printf("%lld\n", query(l, r, 1, n, 1));
    }
  }
  return 0;
}
