#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 7;
struct tree {
  int l, r, col;
  long long sum, lazy;
} tree[mx << 2];
void push_up(int id) {
  tree[id].sum = tree[id << 1].sum + tree[id << 1 | 1].sum;
  if (tree[id << 1].col == tree[id << 1 | 1].col)
    tree[id].col = tree[id << 1].col;
  else
    tree[id].col = 0;
}
void push_down(int id) {
  if (tree[id].lazy) {
    long long x = tree[id].lazy;
    tree[id << 1].lazy += x;
    tree[id << 1 | 1].lazy += x;
    tree[id << 1].sum += x * (tree[id << 1].r - tree[id << 1].l + 1);
    tree[id << 1 | 1].sum +=
        x * (tree[id << 1 | 1].r - tree[id << 1 | 1].l + 1);
    tree[id].lazy = 0;
  }
  if (tree[id].col) {
    tree[id << 1].col = tree[id << 1 | 1].col = tree[id].col;
    tree[id].col = 0;
  }
}
void build(int l, int r, int id) {
  tree[id].l = l;
  tree[id].r = r;
  tree[id].lazy = 0;
  if (l == r) {
    tree[id].sum = 0;
    tree[id].col = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, id << 1);
  build(mid + 1, r, id << 1 | 1);
  push_up(id);
}
void upd(int l, int r, int id, int x) {
  if (tree[id].l >= l && tree[id].r <= r && tree[id].col) {
    tree[id].lazy += abs(tree[id].col - x);
    tree[id].sum +=
        (long long)abs(tree[id].col - x) * (tree[id].r - tree[id].l + 1);
    tree[id].col = x;
    return;
  }
  push_down(id);
  int mid = (tree[id].l + tree[id].r) >> 1;
  if (r <= mid)
    upd(l, r, id << 1, x);
  else if (mid < l)
    upd(l, r, id << 1 | 1, x);
  else
    upd(l, mid, id << 1, x), upd(mid + 1, r, id << 1 | 1, x);
  push_up(id);
}
long long query(int l, int r, int id) {
  if (tree[id].l == l && tree[id].r == r) return tree[id].sum;
  push_down(id);
  int mid = (tree[id].l + tree[id].r) >> 1;
  if (r <= mid) return query(l, r, id << 1);
  if (mid < l) return query(l, r, id << 1 | 1);
  return query(l, mid, id << 1) + query(mid + 1, r, id << 1 | 1);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  while (m--) {
    int op, l, r, x;
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &x);
      upd(l, r, 1, x);
    } else {
      printf("%lld\n", query(l, r, 1));
    }
  }
  return 0;
}
