#include <bits/stdc++.h>
using namespace std;
long long N, Q, op, l, r, v, sol;
long long len = 200, cant;
long long A[100100], sum[100100];
bool full[100100];
long long bsum[100100], first[100100], last[100100], xtra[100100];
long long B[100100];
void block_update(long long block) {
  long long base = block * len;
  if (!full[block]) {
    for (long long I = 0; I < len; I++) {
      long long pos = base + I;
      sum[pos] += abs(A[pos] - v);
      bsum[block] += abs(A[pos] - v);
      A[pos] = v;
    }
    first[block] = v;
  } else {
    xtra[block] += abs(last[block] - v);
    bsum[block] += abs(last[block] - v) * len;
    last[block] = v;
  }
  last[block] = v;
  full[block] = true;
}
void block_query(long long block) { sol += bsum[block]; }
void point_update(long long pos) {
  long long block = pos / len;
  if (block < cant) bsum[block] += abs(A[pos] - v);
  sum[pos] += abs(A[pos] - v);
  A[pos] = v;
}
void point_query(long long pos) { sol += sum[pos]; }
void push(long long block) {
  if (!full[block]) return;
  long long base = block * len;
  for (long long I = 0; I < len; I++) {
    long long pos = base + I;
    sum[pos] += xtra[block];
    A[pos] = last[block];
  }
  xtra[block] = 0;
  full[block] = false;
}
void pull(long long block) {}
void border_push() {
  long long block = r / len;
  if (block < cant) push(block);
  block = l / len;
  if (block < cant) push(block);
}
void border_pull() {
  long long block = r / len;
  if (block < cant) pull(block);
  block = l / len;
  if (block < cant) pull(block);
}
void paint() {
  border_push();
  long long block = l / len;
  long long pos = l % len;
  for (long long I = l; I <= r;)
    if (pos == 0 && I + len <= r) {
      block_update(block);
      I += len;
      block++;
    } else {
      point_update(I);
      I++, pos++;
      if (pos == len) pos = 0, block++;
    }
  border_pull();
}
void print() {
  sol = 0;
  border_push();
  long long block = l / len;
  long long pos = l % len;
  for (long long I = l, p = l % len; I <= r;)
    if (p == 0 && I + len <= r) {
      block_query(block);
      I += len;
      block++;
    } else {
      point_query(I);
      I++, p++;
      if (p == len) p = 0, block++;
    }
  border_pull();
  cout << sol << "\n";
}
void init() {
  for (long long I = 0; I < N; I++) A[I] = I + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> Q;
  cant = N / len;
  init();
  while (Q--) {
    cin >> op >> l >> r;
    l--, r--;
    if (op == 1) {
      cin >> v;
      paint();
    } else if (op == 2) {
      print();
    } else
      assert(false);
  }
}
