#include <bits/stdc++.h>
using namespace std;
const long long MAXn = 1e5 + 10, SQ = 250;
pair<int, int> ar[MAXn];
vector<int> colors[SQ + 200];
long long partial[MAXn], score[MAXn], score2[SQ + 200], n, m;
void query1(long long st, long long en, long long x) {
  for (long long i = 0; i < n; i += SQ) {
    long long en1 = min(i + SQ, n);
    if (st <= i && en1 <= en) {
      if (colors[i / SQ].empty()) {
        long long hp =
            lower_bound(ar + i, ar + en1, pair<int, int>(x, -1)) - ar;
        if (hp == i)
          score2[i / SQ] += 1ll * partial[en1 - 1] - 1ll * (en1 - i) * x;
        else
          score2[i / SQ] += 1ll * partial[en1 - 1] - 2LL * partial[hp - 1] +
                            1ll * (-(en1 - hp) + (hp - i)) * x;
      } else
        score2[i / SQ] += 1ll * (en1 - i) * abs(colors[i / SQ].back() - x);
      colors[i / SQ].push_back(x);
    } else if (min(en, en1) > max(st, i) || st >= i && en1 >= en) {
      if (!colors[i / SQ].empty()) {
        long long addscore = 0;
        for (long long j = 1; j < 1ll * colors[i / SQ].size(); j++)
          addscore += abs(colors[i / SQ][j] - colors[i / SQ][j - 1]);
        for (long long j = i; j < en1; j++) {
          score[ar[j].second] +=
              addscore + abs(ar[j].first - colors[i / SQ][0]);
          ar[j].first = colors[i / SQ].back();
        }
        colors[i / SQ].clear();
      }
      for (long long j = i; j < en1; j++)
        if (ar[j].second >= st && ar[j].second < en) {
          score[ar[j].second] += abs(ar[j].first - x);
          score2[i / SQ] += abs(ar[j].first - x);
          ar[j].first = x;
        }
      sort(ar + i, ar + en1);
      partial[i] = ar[i].first;
      for (long long j = i + 1; j < en1; j++)
        partial[j] = partial[j - 1] + ar[j].first;
    }
  }
}
long long query2(long long st, long long en) {
  long long ans = 0;
  for (long long i = 0; i < n; i += SQ) {
    long long en1 = min(1ll * (i + SQ), n);
    if (st <= i && en1 <= en)
      ans += score2[i / SQ];
    else if (min(en, en1) > max(st, i) || st >= i && en1 >= en) {
      if (!colors[i / SQ].empty()) {
        long long addscore = 0;
        for (long long j = 1; j < 1ll * colors[i / SQ].size(); j++)
          addscore += abs(colors[i / SQ][j] - colors[i / SQ][j - 1]);
        for (long long j = i; j < en1; j++) {
          score[ar[j].second] +=
              addscore + abs(ar[j].first - colors[i / SQ][0]);
          ar[j].first = colors[i / SQ].back();
        }
        colors[i / SQ].clear();
        partial[i] = ar[i].first;
        for (long long j = i + 1; j < en1; j++)
          partial[j] = partial[j - 1] + ar[j].first;
      }
      for (long long j = i; j < en1; j++)
        if (ar[j].second >= st && ar[j].second < en) ans += score[ar[j].second];
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) ar[i] = pair<int, int>(i, i);
  for (long long i = 0; i < n; i++) {
    if (i % SQ == 0)
      partial[i] = i;
    else
      partial[i] = partial[i - 1] + i;
  }
  for (long long i = 0; i < m; i++) {
    long long typeq;
    cin >> typeq;
    if (typeq == 1) {
      long long st, en, x;
      cin >> st >> en >> x;
      st--;
      x--;
      query1(st, en, x);
    } else {
      long long st, en;
      cin >> st >> en;
      st--;
      cout << query2(st, en) << '\n';
    }
  }
}
