#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
struct Node {
  int l, r, co;
  long long val, lz;
  Node() {
    lz = 0LL;
    co = -1;
    val = 0LL;
  }
} t[N << 2];
int n, m, l, r, x, flag;
long long ABS(long long x) { return x > 0LL ? x : -x; }
void build(int rt, int l, int r) {
  t[rt].l = l;
  t[rt].r = r;
  t[rt].lz = 0;
  t[rt].co = -1;
  if (l == r) {
    t[rt].co = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void print(int rt) {
  if (t[rt].l == t[rt].r) return;
  print(rt << 1);
  print(rt << 1 | 1);
}
void pushdown(int rt) {
  if (t[rt].l == t[rt].r) return;
  if (t[rt].lz > 0LL) {
    t[rt << 1].val += (t[rt << 1].r - t[rt << 1].l + 1) * t[rt].lz;
    t[rt << 1].lz += t[rt].lz;
    t[rt << 1 | 1].val += (t[rt << 1 | 1].r - t[rt << 1 | 1].l + 1) * t[rt].lz;
    t[rt << 1 | 1].lz += t[rt].lz;
    t[rt].lz = 0LL;
  }
  if (t[rt].co > 0) t[rt << 1].co = t[rt << 1 | 1].co = t[rt].co;
  return;
}
void pushup(int rt) {
  if (t[rt].l == t[rt].r) return;
  if (t[rt << 1].co == t[rt << 1 | 1].co && t[rt << 1].co > 0)
    t[rt].co = t[rt << 1].co;
  else
    t[rt].co = -1;
  t[rt].val = t[rt << 1].val + t[rt << 1 | 1].val;
  return;
}
void insert(int rt, int l, int r, int co) {
  pushdown(rt);
  if (t[rt].l == l && t[rt].r == r && t[rt].co > 0) {
    t[rt].val += 1LL * (t[rt].r - t[rt].l + 1) * abs(co - t[rt].co);
    t[rt].lz += 1LL * abs(co - t[rt].co);
    t[rt].co = co;
    return;
  }
  int mid = (t[rt].l + t[rt].r) >> 1;
  if (r <= mid)
    insert(rt << 1, l, r, co);
  else if (l > mid)
    insert(rt << 1 | 1, l, r, co);
  else {
    insert(rt << 1, l, mid, co);
    insert(rt << 1 | 1, mid + 1, r, co);
  }
  pushup(rt);
}
long long query(int rt, int l, int r) {
  pushdown(rt);
  if (t[rt].l == l && t[rt].r == r) {
    return t[rt].val;
  }
  int mid = (t[rt].l + t[rt].r) >> 1;
  if (r <= mid)
    return query(rt << 1, l, r);
  else if (l > mid)
    return query(rt << 1 | 1, l, r);
  else {
    return query(rt << 1, l, mid) + query(rt << 1 | 1, mid + 1, r);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int flag;
    scanf("%d", &flag);
    if (flag == 1) {
      scanf("%d%d%d", &l, &r, &x);
      insert(1, l, r, x);
    } else {
      scanf("%d%d", &l, &r);
      cout << query(1, l, r) << endl;
    }
  }
  return 0;
}
