#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 18) + 5;
int N, M;
long long seg[MAXN];
long long lazy[MAXN];
int color[MAXN];
void build_tree(int node, int left, int right) {
  if (left > right) return;
  if (left == right) {
    color[node] = left;
    return;
  }
  build_tree(2 * node, left, (left + right) / 2);
  build_tree(2 * node + 1, (left + right) / 2 + 1, right);
}
void check_lazy(int node, int left, int right) {
  if (lazy[node] > 0) {
    if (left < right) {
      lazy[2 * node] += lazy[node];
      lazy[2 * node + 1] += lazy[node];
      seg[2 * node] += lazy[node] * ((left + right) / 2 - left + 1);
      seg[2 * node + 1] += lazy[node] * (right - (left + right) / 2);
      if (color[node] > 0) {
        color[2 * node] = color[node];
        color[2 * node + 1] = color[node];
      }
    }
    lazy[node] = 0;
  }
}
void update(int node, int left, int right, int ql, int qr, int x) {
  if (left > right || left > qr || right < ql) return;
  if (ql <= left && right <= qr && color[node] > 0) {
    seg[node] += (long long)abs(x - color[node]) * (right - left + 1);
    lazy[node] += abs(x - color[node]);
    color[node] = x;
    return;
  }
  check_lazy(node, left, right);
  update(2 * node, left, (left + right) / 2, ql, qr, x);
  update(2 * node + 1, (left + right) / 2 + 1, right, ql, qr, x);
  seg[node] = seg[2 * node] + seg[2 * node + 1];
  if (ql <= left && right <= qr)
    color[node] = x;
  else
    color[node] = 0;
}
long long query(int node, int left, int right, int ql, int qr) {
  if (left > right || left > qr || right < ql) return 0;
  if (ql <= left && right <= qr) return seg[node];
  check_lazy(node, left, right);
  return query(2 * node, left, (left + right) / 2, ql, qr) +
         query(2 * node + 1, (left + right) / 2 + 1, right, ql, qr);
}
int main() {
  cin >> N >> M;
  build_tree(1, 1, N);
  for (int i = 0; i < M; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int ql, qr, x;
      cin >> ql >> qr >> x;
      update(1, 1, N, ql, qr, x);
    } else {
      int ql, qr;
      cin >> ql >> qr;
      cout << query(1, 1, N, ql, qr) << "\n";
    }
  }
  return 0;
}
