#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 100005;
struct node {
  long long sum, del;
  int x;
} s[maxn << 2];
void updata(int root, int l, int r) {
  s[root].sum =
      s[root << 1].sum + s[root << 1 | 1].sum + 1LL * (r - l + 1) * s[root].del;
}
void build(int root, int l, int r) {
  s[root].sum = s[root].del = 0;
  s[root].x = 0;
  if (l == r) {
    s[root].sum = 0;
    s[root].x = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
}
void gao(int root, int l, int r, int x) {
  if (s[root].x) {
    s[root].del += abs(s[root].x - x);
    s[root].sum += 1LL * (r - l + 1) * abs(s[root].x - x);
  } else {
    int mid = (l + r) >> 1;
    gao(root << 1, l, mid, x);
    gao(root << 1 | 1, mid + 1, r, x);
    updata(root, l, r);
  }
}
void paint(int l, int r, int root, int ll, int rr, int x) {
  if (l > rr || r < ll) return;
  if (ll <= l && r <= rr) {
    gao(root, l, r, x);
    s[root].x = x;
    return;
  }
  if (s[root].x) {
    s[root << 1].x = s[root].x;
    s[root << 1 | 1].x = s[root].x;
    s[root].x = 0;
  }
  int mid = (l + r) >> 1;
  paint(l, mid, root << 1, ll, rr, x);
  paint(mid + 1, r, root << 1 | 1, ll, rr, x);
  updata(root, l, r);
}
long long query(int l, int r, int root, int ll, int rr) {
  if (l > rr || r < ll) return 0;
  if (ll <= l && rr >= r) return s[root].sum;
  int mid = (l + r) >> 1;
  return query(l, mid, root << 1, ll, rr) +
         query(mid + 1, r, root << 1 | 1, ll, rr) +
         s[root].del * (min(rr, r) - max(ll, l) + 1);
}
int n, m;
int main() {
  int l, r, x, typ;
  scanf("%d%d", &n, &m);
  build(1, 1, n);
  while (m--) {
    scanf("%d", &typ);
    scanf("%d%d", &l, &r);
    if (typ == 1) {
      scanf("%d", &x);
      paint(1, n, 1, l, r, x);
    } else {
      printf("%I64d\n", query(1, n, 1, l, r));
    }
  }
  return 0;
}
