#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;
struct fenwick {
  int n;
  vector<ll> a, b;
  fenwick(int s) {
    n = s;
    a.assign(n + 1, 0);
    b.assign(n + 1, 0);
  }
  void update(vector<ll>& bit, int idx, ll v) {
    for (int i = idx; i <= n; i += (i & -i)) bit[i] += v;
  }
  void update(int l, int r, ll v) {
    update(a, l, v);
    update(a, r + 1, -v);
    update(b, l, -v * (l - 1));
    update(b, r + 1, v * r);
  }
  ll query(vector<ll> const& bit, ll idx) {
    ll sum = 0;
    for (int i = idx; i > 0; i -= (i & -i)) sum += bit[i];
    return sum;
  }
  ll query(int idx) { return query(a, idx) * idx + query(b, idx); }
  ll query(int l, int r) { return query(r) - query(l - 1); }
};
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  fenwick ft(n);
  map<int, pair<int, int>> s;
  for (int i = 1; i <= n; ++i) s[i] = {i, i};
  while (m--) {
    int t, l, r;
    cin >> t >> l >> r;
    if (t & 1) {
      int v;
      cin >> v;
      for (auto it = s.lower_bound(l); it != s.end();) {
        int x, y = it->first, z;
        tie(x, z) = it->second;
        int L = max(l, x);
        int R = min(r, y);
        if (L > R) break;
        s.erase(it++);
        if (x < L) s[L - 1] = {x, z};
        if (R < y) s[y] = {R + 1, z};
        ft.update(L, R, abs(v - z));
      }
      s[r] = {l, v};
    } else {
      cout << ft.query(l, r) << "\n";
    }
  }
}
