#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct Segment {
  int l, r, col;
  Segment() {}
  Segment(int _l, int _r, int _c) : l(_l), r(_r), col(_c) {}
  bool operator<(const Segment &s) const { return l < s.l; }
};
int n, q;
set<Segment> s;
long long a[N], b[N];
inline int lowbit(int x) { return x & (-x); }
void add(long long *a, int x, long long c) {
  for (int i = x; i <= n; i += lowbit(i)) a[i] += c;
}
long long ask(long long *a, int x) {
  long long ret = 0;
  for (int i = x; i; i -= lowbit(i)) ret += a[i];
  return ret;
}
void update(int l, int r, long long c) {
  add(a, l, c);
  add(a, r + 1, -c);
  add(b, l, (l - 1LL) * c);
  add(b, r + 1, -1LL * r * c);
}
long long query(int l, int r) {
  return r * ask(a, r) - ask(b, r) - ((l - 1) * ask(a, l - 1) - ask(b, l - 1));
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) s.insert(Segment(i, i, i));
  while (q--) {
    int type, l, r, col;
    scanf("%d %d %d", &type, &l, &r);
    if (type == 1) {
      scanf("%d", &col);
      set<Segment>::iterator it = s.upper_bound(Segment(l, n + 1, 0));
      it--;
      vector<Segment> er, ad;
      while (it != s.end()) {
        if (it->l > r) break;
        update(max(l, it->l), min(r, it->r), abs(it->col - col));
        if (it->l < l) ad.push_back(Segment(it->l, l - 1, it->col));
        if (it->r > r) ad.push_back(Segment(r + 1, it->r, it->col));
        er.push_back(*it);
        it++;
      }
      for (int i = 0; i < er.size(); i++) {
        s.erase(s.find(er[i]));
      }
      for (int i = 0; i < ad.size(); i++) {
        s.insert(ad[i]);
      }
      s.insert(Segment(l, r, col));
    } else {
      printf("%I64d\n", query(l, r));
    }
  }
  return 0;
}
