#include <bits/stdc++.h>
using namespace std;
namespace cheapwine {
template <class C>
int size(C const& c) {
  return c.size();
}
}  // namespace cheapwine
using namespace cheapwine;
int m, n;
struct sqrtdecomposite {
  struct group {
    bool same, dirty;
    int gv, fixdirty;
    long long gdelta, gf;
    vector<int> cv;
    vector<long long> cf;
    group(int count) : cv(count), cf(count) {
      dirty = same = 0;
      gdelta = 0;
      gv = 0;
      gf = 0;
      fixdirty = 0;
    }
    void clean() {
      if (dirty) {
        for (int i = 0; i < size(cv); ++i) {
          int delta = abs(cv[i] - fixdirty);
          cf[i] += delta;
          gf += delta;
        }
        dirty = 0;
      }
    }
    void set(int x) {
      if (!same) {
        dirty = 1;
        fixdirty = x;
        same = 1;
        gv = x;
      } else {
        gdelta += llabs(gv - x);
        gv = x;
      };
      ;
      ;
    }
    int getvalue(int pos) {
      if (same) return gv;
      return cv[pos];
    }
    void set(int lp, int rp, int x) {
      if (lp <= 0 && rp >= size(cv) - 1) {
        set(x);
        return;
      } else {
        clean();
        if (same)
          for (int i = 0; i < size(cv); ++i) cv[i] = gv;
        for (int i = lp; i <= rp; ++i) {
          int delta = abs(x - cv[i]);
          if (delta) {
            same = 0;
            cf[i] += delta;
            gf += delta;
            cv[i] = x;
          }
        }
      };
      ;
      ;
    }
    long long query() {
      clean();
      ;
      ;
      ;
      return gf + gdelta * size(cv);
    }
    long long query(int lp, int rp) {
      if (lp <= 0 && rp >= size(cv) - 1) {
        return query();
      }
      long long ret = 0;
      clean();
      for (int i = lp; i <= rp; ++i) ret += cf[i];
      return ret + gdelta * (rp - lp + 1);
    }
  };
  int n, sqrtn;
  vector<group> data;
  sqrtdecomposite(int n) : n(n), sqrtn((int)sqrt(n)) {
    int left = n;
    while (left) {
      int cnt = min(left, sqrtn);
      data.push_back(group(cnt));
      left -= cnt;
    };
  }
  int& operator[](int pos) { return data[pos / sqrtn].cv[pos % sqrtn]; }
  void rangeset(int l, int r, int x) {
    int lg = l / sqrtn, rg = r / sqrtn, lp = l % sqrtn, rp = r % sqrtn;
    if (lg == rg) {
      data[lg].set(lp, rp, x);
    } else {
      assert(lg < rg);
      data[lg].set(lp, sqrtn - 1, x);
      for (int i = lg + 1; i < rg; ++i) data[i].set(x);
      data[rg].set(0, rp, x);
    }
  }
  long long query(int l, int r) {
    int lg = l / sqrtn, rg = r / sqrtn, lp = l % sqrtn, rp = r % sqrtn;
    long long ret = 0;
    ;
    ;
    if (lg == rg) {
      ret = data[lg].query(lp, rp);
      return ret;
    } else {
      ret = data[lg].query(lp, sqrtn - 1);
      for (int i = lg + 1; i < rg; ++i) ret += data[i].query();
      ret += data[rg].query(0, rp);
      return ret;
    }
  }
};
void contest_main() {
  cin >> n >> m;
  sqrtdecomposite d(n);
  for (int i = 0; i < n; ++i) d[i] = i + 1;
  ;
  ;
  for (remove_cv<__typeof(m)>::type i = 0; i < (m); ++i) {
    int type;
    cin >> type;
    int l, r, x;
    ;
    ;
    if (type == 1) {
      cin >> l >> r >> x;
      --l;
      --r;
      ;
      ;
      d.rangeset(l, r, x);
    } else {
      assert(type == 2);
      cin >> l >> r;
      --l;
      --r;
      ;
      ;
      cout << d.query(l, r) << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  contest_main();
  return 0;
}
