#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
struct node {
  long long l, r;
  long long color;
  long long sum;
  long long change;
} tree[maxn << 2];
long long n, m;
int a[maxn];
void pushup(long long cur) {
  if (tree[cur * 2].color == tree[cur * 2 + 1].color)
    tree[cur].color = tree[cur * 2].color;
  tree[cur].sum = tree[cur * 2].sum + tree[cur * 2 + 1].sum;
}
void build(long long l, long long r, long long cur) {
  tree[cur].l = l;
  tree[cur].r = r;
  tree[cur].sum = 0;
  tree[cur].change = 0;
  tree[cur].color = 0;
  if (l == r) {
    tree[cur].color = l;
    return;
  }
  long long mid = (r + l) >> 1;
  build(l, mid, cur << 1);
  build(mid + 1, r, cur << 1 | 1);
  pushup(cur);
}
void pushdown(long long cur) {
  if (tree[cur].change) {
    tree[cur * 2].sum +=
        tree[cur].change * (tree[cur * 2].r - tree[cur * 2].l + 1);
    tree[cur * 2 + 1].sum +=
        tree[cur].change * (tree[cur * 2 + 1].r - tree[cur * 2 + 1].l + 1);
    tree[cur * 2].change += tree[cur].change;
    tree[cur * 2 + 1].change += tree[cur].change;
    tree[cur].change = 0;
  }
  if (tree[cur].color)
    tree[cur * 2].color = tree[cur * 2 + 1].color = tree[cur].color;
  tree[cur].color = 0;
}
void update(long long pl, long long pr, long long l, long long r, long long cur,
            long long x) {
  if ((pl <= l && r <= pr && tree[cur].color) || l == r) {
    tree[cur].sum += abs(x - tree[cur].color) * (r - l + 1);
    tree[cur].change += abs(x - tree[cur].color);
    tree[cur].color = x;
    return;
  }
  pushdown(cur);
  long long mid = (r + l) >> 1;
  if (pl <= mid) update(pl, pr, l, mid, cur << 1, x);
  if (pr > mid) update(pl, pr, mid + 1, r, cur << 1 | 1, x);
  pushup(cur);
}
long long query(long long pl, long long pr, long long l, long long r,
                long long cur) {
  if (pl <= l && r <= pr) {
    return tree[cur].sum;
  }
  pushdown(cur);
  long long mid = (r + l) >> 1;
  long long res = 0;
  if (pl <= mid) res += query(pl, pr, l, mid, cur << 1);
  if (pr > mid) res += query(pl, pr, mid + 1, r, cur << 1 | 1);
  return res;
}
int main() {
  while (~scanf("%lld%lld", &n, &m)) {
    build(1, n, 1);
    long long op, l, r, x;
    while (m--) {
      scanf("%lld%lld%lld", &op, &l, &r);
      if (op == 1) {
        scanf("%lld", &x);
        update(l, r, 1, n, 1, x);
      } else {
        printf("%lld\n", query(l, r, 1, n, 1));
      }
    }
  }
  return 0;
}
