#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 100;
struct node {
  int l;
  int r;
  long long v;
  long long cor;
  long long lazy;
} p[maxx << 2];
int n, m;
void pushup(int cur) {
  p[cur].v = p[cur << 1].v + p[cur << 1 | 1].v;
  p[cur].cor = (p[cur << 1].cor == p[cur << 1 | 1].cor) ? p[cur << 1].cor : 0;
}
void pushdown(int cur) {
  if (p[cur].cor && p[cur].lazy) {
    p[cur << 1].lazy += p[cur].lazy;
    p[cur << 1 | 1].lazy += p[cur].lazy;
    p[cur << 1].v +=
        abs(p[cur].lazy) * (long long)(p[cur << 1].r - p[cur << 1].l + 1);
    p[cur << 1 | 1].v += abs(p[cur].lazy) *
                         (long long)(p[cur << 1 | 1].r - p[cur << 1 | 1].l + 1);
    p[cur << 1].cor = p[cur << 1 | 1].cor = p[cur].cor;
    p[cur].lazy = 0;
  }
}
void build(int l, int r, int cur) {
  p[cur].l = l;
  p[cur].r = r;
  p[cur].v = p[cur].lazy = 0;
  if (l == r) {
    p[cur].cor = (long long)l;
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, cur << 1);
  build(mid + 1, r, cur << 1 | 1);
  pushup(cur);
}
void update(int cur, int l, int r, long long c) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (p[cur].cor == c) return;
  if (l <= L && R <= r && p[cur].cor) {
    p[cur].v += abs(p[cur].cor - c) * (long long)(R - L + 1);
    p[cur].lazy += abs(c - p[cur].cor);
    p[cur].cor = c;
    return;
  }
  pushdown(cur);
  int mid = L + R >> 1;
  if (r <= mid)
    update(cur << 1, l, r, c);
  else if (l > mid)
    update(cur << 1 | 1, l, r, c);
  else {
    update(cur << 1, l, mid, c);
    update(cur << 1 | 1, mid + 1, r, c);
  }
  pushup(cur);
}
long long query(int cur, int l, int r) {
  int L = p[cur].l;
  int R = p[cur].r;
  if (l <= L && R <= r) {
    return p[cur].v;
  }
  pushdown(cur);
  int mid = L + R >> 1;
  long long ans = 0;
  if (r <= mid)
    ans = query(cur << 1, l, r);
  else if (l > mid)
    ans = query(cur << 1 | 1, l, r);
  else
    ans = query(cur << 1, l, mid) + query(cur << 1 | 1, mid + 1, r);
  pushup(cur);
  return ans;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    build(1, n, 1);
    int op, l, r;
    long long c;
    while (m--) {
      scanf("%d%d%d", &op, &l, &r);
      if (op == 1) {
        scanf("%lld", &c);
        update(1, l, r, c);
      } else if (op == 2)
        printf("%lld\n", query(1, l, r));
    }
  }
  return 0;
}
