#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 20;
int n, m;
struct node {
  int fcol, lcol, val, lazy;
} seg[N << 2];
void build(int v = 1, int s = 0, int e = n) {
  if (e - s == 1) {
    seg[v].fcol = seg[v].lcol = s + 1;
    return;
  }
  seg[v].fcol = seg[v].lcol = -1;
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  build(lc, s, mid);
  build(rc, mid, e);
}
inline void shift(int v, int s, int e) {
  if (seg[v].fcol == -1) {
    return;
  }
  int lc = v << 1, rc = lc | 1, mid = (s + e) >> 1;
  int add1 = abs(seg[v].fcol - seg[lc].lcol) + seg[v].lazy;
  seg[lc].val += add1 * (mid - s);
  seg[lc].lazy += add1;
  seg[lc].lcol = seg[v].lcol;
  int add2 = abs(seg[v].fcol - seg[rc].lcol) + seg[v].lazy;
  seg[rc].val += add2 * (e - mid);
  seg[rc].lazy += add2;
  seg[rc].lcol = seg[v].lcol;
  seg[v].lazy = 0;
  seg[v].fcol = seg[v].lcol = -1;
}
void modify(int l, int r, int c, int v = 1, int s = 0, int e = n) {
  if (s >= r || e <= l) {
    return;
  }
  if (s >= l && e <= r && seg[v].fcol != -1) {
    int add = abs(c - seg[v].lcol);
    seg[v].val += add * (e - s);
    seg[v].lazy += add;
    seg[v].lcol = c;
    return;
  }
  shift(v, s, e);
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  modify(l, r, c, lc, s, mid);
  modify(l, r, c, rc, mid, e);
  seg[v].val = seg[lc].val + seg[rc].val;
  if (s >= l && e <= r) {
    seg[v].fcol = seg[v].lcol = c;
  }
}
int get(int l, int r, int v = 1, int s = 0, int e = n) {
  if (s >= r || e <= l) {
    return 0;
  }
  if (s >= l && e <= r) {
    return seg[v].val;
  }
  shift(v, s, e);
  int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;
  return get(l, r, lc, s, mid) + get(l, r, rc, mid, e);
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  build();
  while (m--) {
    int type, l, r, c;
    cin >> type;
    cin >> l >> r;
    l--;
    if (type == 1) {
      cin >> c;
      modify(l, r, c);
    } else {
      cout << get(l, r) << '\n';
    }
  }
}
