#include <bits/stdc++.h>
using namespace std;
const int64_t maxn = 1e5 + 10;
int64_t n;
struct range {
  int64_t l, r;
  int64_t v;
  range(int64_t l = 0) : l(l) {}
  range(int64_t l, int64_t r, int64_t v) : l(l), r(r), v(v) {}
  bool operator<(range const& T) const { return l < T.l; }
};
ostream& operator<<(ostream& out, range const& T) {
  out << "(" << T.l << ", " << T.r << ", " << T.v << ")";
  return out;
}
struct special_set : set<range> {
  vector<range> remove(int64_t l, int64_t r) {
    vector<range> ans;
    if (l >= r) return ans;
    auto it = lower_bound(l);
    if (it != begin()) {
      it--;
      if (it->r > l) {
        auto aux = *it;
        erase(it);
        emplace(aux.l, l, aux.v);
        emplace(l, aux.r, aux.v);
      }
    }
    it = lower_bound(r);
    if (it != begin()) {
      it--;
      if (it->r > r) {
        auto aux = *it;
        erase(it);
        emplace(aux.l, r, aux.v);
        emplace(r, aux.r, aux.v);
      }
    }
    auto itl = lower_bound(l);
    auto itr = itl;
    for (; itr != end() && itr->l < r; itr++) ans.push_back(*itr);
    erase(itl, itr);
    return ans;
  }
  vector<range> update(int64_t l, int64_t r, int64_t v) {
    auto ans = remove(l, r);
    emplace(l, r, v);
    return ans;
  }
};
int64_t tree[4 * maxn];
int64_t lazy[4 * maxn];
void flush(int64_t seg, int64_t ini, int64_t fim) {
  if (lazy[seg] == 0) return;
  tree[seg] += lazy[seg] * (fim - ini + 1);
  if (ini != fim) {
    lazy[seg << 1] += lazy[seg];
    lazy[seg << 1 | 1] += lazy[seg];
  }
  lazy[seg] = 0;
}
void update(int64_t l, int64_t r, int64_t v, int64_t seg = 1, int64_t ini = 1,
            int64_t fim = n) {
  flush(seg, ini, fim);
  if (fim < l || ini > r) return;
  if (l <= ini && fim <= r) {
    lazy[seg] = v;
    flush(seg, ini, fim);
    return;
  }
  int64_t meio = ini + fim >> 1;
  update(l, r, v, seg << 1, ini, meio);
  update(l, r, v, seg << 1 | 1, meio + 1, fim);
  tree[seg] = tree[seg << 1] + tree[seg << 1 | 1];
}
int64_t query(int64_t l, int64_t r, int64_t seg = 1, int64_t ini = 1,
              int64_t fim = n) {
  flush(seg, ini, fim);
  if (fim < l || ini > r) return 0;
  if (l <= ini && fim <= r) return tree[seg];
  int64_t meio = ini + fim >> 1;
  int64_t p1 = query(l, r, seg << 1, ini, meio);
  int64_t p2 = query(l, r, seg << 1 | 1, meio + 1, fim);
  return p1 + p2;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int64_t m;
  cin >> n >> m;
  special_set T;
  for (int64_t i = 1; i <= n; i++) T.emplace(i, i + 1, i);
  while (m--) {
    int64_t t;
    cin >> t;
    if (t == 1) {
      int64_t l, r, x;
      cin >> l >> r >> x;
      auto ans = T.update(l, r + 1, x);
      for (auto& e : ans) {
        update(e.l, e.r - 1, abs(x - e.v));
      }
    } else {
      int64_t l, r;
      cin >> l >> r;
      cout << query(l, r) << '\n';
    }
  }
  return 0;
}
