#include <bits/stdc++.h>
using namespace std;
const int AX = 1e5 + 66;
int tot;
struct Node {
  int col;
  long long sum;
  long long lazy;
} s[AX << 2];
void pushUp(int rt) {
  s[rt].sum = s[rt << 1].sum + s[rt << 1 | 1].sum;
  if (s[rt << 1].col == s[rt << 1 | 1].col) {
    s[rt].col = s[rt << 1].col;
  } else
    s[rt].col = 0;
  return;
}
void pushDown(int rt, int L, int R) {
  if (s[rt].col && s[rt].lazy) {
    int mid = (L + R) >> 1;
    s[rt << 1].col = s[rt].col;
    s[rt << 1 | 1].col = s[rt].col;
    s[rt << 1].sum += (mid - L + 1) * s[rt].lazy;
    s[rt << 1 | 1].sum += (R - mid) * s[rt].lazy;
    s[rt << 1].lazy += s[rt].lazy;
    s[rt << 1 | 1].lazy += s[rt].lazy;
    s[rt].lazy = 0;
  }
  return;
}
void build(int l, int r, int rt) {
  if (l == r) {
    s[rt].col = ++tot;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushUp(rt);
}
void update(int L, int R, int v, int l, int r, int rt) {
  if (L <= l && R >= r && s[rt].col) {
    s[rt].sum +=
        (long long)((long long)(r - l + 1) * (long long)abs(v - s[rt].col));
    s[rt].lazy += abs(v - s[rt].col);
    s[rt].col = v;
    return;
  }
  pushDown(rt, l, r);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, v, l, mid, rt << 1);
  if (R > mid) update(L, R, v, mid + 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 s[rt].sum;
  }
  pushDown(rt, l, r);
  long long ans = 0LL;
  int mid = (l + r) >> 1;
  if (L <= mid) ans += query(L, R, l, mid, rt << 1);
  if (R > mid) ans += query(L, R, mid + 1, r, rt << 1 | 1);
  pushUp(rt);
  return ans;
}
int main() {
  int n, m;
  int op;
  int l, r, x;
  scanf("%d%d", &n, &m);
  tot = 0;
  build(1, n, 1);
  while (m--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d", &l, &r, &x);
      update(l, r, x, 1, n, 1);
    } else {
      scanf("%d%d", &l, &r);
      printf("%I64d\n", query(l, r, 1, n, 1));
    }
  }
  return 0;
}
