#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct node {
  int l, r, col;
  long long lazy, sum;
} tr[maxn << 2];
void pushup(int m) {
  tr[m].sum = tr[m << 1].sum + tr[m << 1 | 1].sum;
  tr[m].col = tr[m << 1].col == tr[m << 1 | 1].col ? tr[m << 1].col : 0;
}
void pushdown(int m) {
  if (tr[m].col) {
    tr[m << 1].col = tr[m << 1 | 1].col = tr[m].col;
    tr[m << 1].sum += tr[m].lazy * (long long)(tr[m << 1].r - tr[m << 1].l + 1);
    tr[m << 1 | 1].sum +=
        tr[m].lazy * (long long)(tr[m << 1 | 1].r - tr[m << 1 | 1].l + 1);
    tr[m << 1].lazy += tr[m].lazy;
    tr[m << 1 | 1].lazy += tr[m].lazy;
    tr[m].lazy = 0;
  }
}
void build(int m, int l, int r) {
  tr[m].l = l;
  tr[m].r = r;
  tr[m].lazy = 0;
  if (l == r) {
    tr[m].col = l;
    tr[m].sum = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build(m << 1, l, mid);
  build(m << 1 | 1, mid + 1, r);
  pushup(m);
}
void updata(int m, int l, int r, int val) {
  if (tr[m].col && tr[m].l == l && tr[m].r == r) {
    tr[m].sum +=
        (long long)(tr[m].r - tr[m].l + 1) * (long long)abs(val - tr[m].col);
    tr[m].lazy += (long long)abs(val - tr[m].col);
    tr[m].col = val;
    return;
  }
  pushdown(m);
  int mid = (tr[m].l + tr[m].r) >> 1;
  if (r <= mid)
    updata(m << 1, l, r, val);
  else if (l > mid)
    updata(m << 1 | 1, l, r, val);
  else {
    updata(m << 1, l, mid, val);
    updata(m << 1 | 1, mid + 1, r, val);
  }
  pushup(m);
}
long long query(int m, int l, int r) {
  if (tr[m].l == l && tr[m].r == r) {
    return tr[m].sum;
  }
  pushdown(m);
  int mid = (tr[m].l + tr[m].r) >> 1;
  long long temp;
  if (r <= mid)
    temp = query(m << 1, l, r);
  else if (l > mid)
    temp = query(m << 1 | 1, l, r);
  else {
    temp = query(m << 1, l, mid) + query(m << 1 | 1, mid + 1, r);
  }
  pushup(m);
  return temp;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  while (m--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      updata(1, l, r, x);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%lld\n", query(1, l, r));
    }
  }
  return 0;
}
