#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1 << 17;
ll C[2 * N], V[2 * N], L[2 * N], n, m, t, l, r, x;
void push(int x, int lx, int rx) {
  V[x] += (rx - lx + 1) * L[x];
  if (x < N) {
    L[2 * x] += L[x];
    L[2 * x + 1] += L[x];
    if (C[x]) C[2 * x] = C[2 * x + 1] = C[x];
  }
  L[x] = 0;
}
void maintain(int x) {
  V[x] = V[2 * x] + V[2 * x + 1];
  C[x] = C[2 * x] == C[2 * x + 1] ? C[2 * x] : 0;
}
void update(int x, int lx, int rx, int l, int r, ll c) {
  if (lx > r || rx < l) return;
  if (l <= lx && rx <= r && C[x]) {
    L[x] += abs(c - C[x]);
    C[x] = c;
    return;
  }
  int mid = (lx + rx) / 2;
  push(x, lx, rx);
  update(2 * x, lx, mid, l, r, c);
  update(2 * x + 1, mid + 1, rx, l, r, c);
  push(2 * x, lx, mid);
  push(2 * x + 1, mid + 1, rx);
  maintain(x);
}
ll query(int x, int lx, int rx, int l, int r) {
  if (lx > r || rx < l) return 0;
  push(x, lx, rx);
  if (l <= lx && rx <= r) return V[x];
  int mid = (lx + rx) / 2;
  return query(2 * x, lx, mid, l, r) + query(2 * x + 1, mid + 1, rx, l, r);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) C[N + i] = i;
  while (m--) {
    cin >> t >> l >> r;
    if (t == 1) {
      cin >> x;
      update(1, 0, N - 1, l, r, x);
    } else {
      cout << query(1, 0, N - 1, l, r) << endl;
    }
  }
}
