#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
struct RangeIncrement {
  vector<long long> tree, lazy;
  RangeIncrement(int n) : tree(n << 2), lazy(n << 2) {}
  void refresh(int i, int l, int r) {
    if (lazy[i] != 0) {
      tree[i] += lazy[i] * (r - l + 1);
      if (l < r) {
        int lc = i << 1, rc = (i << 1) + 1;
        lazy[lc] += lazy[i];
        lazy[rc] += lazy[i];
      }
      lazy[i] = 0;
    }
  }
  void update(int i, int l, int r, int ul, int ur, long long x) {
    refresh(i, l, r);
    if (r < ul || l > ur) {
      return;
    } else if (ul <= l && r <= ur) {
      lazy[i] += x;
      refresh(i, l, r);
    } else {
      int m = l + r >> 1;
      int lc = i << 1, rc = (i << 1) + 1;
      update(lc, l, m, ul, ur, x);
      update(rc, m + 1, r, ul, ur, x);
      tree[i] = tree[lc] + tree[rc];
    }
  }
  long long query(int i, int l, int r, int ql, int qr) {
    refresh(i, l, r);
    if (r < ql || l > qr) {
      return 0;
    } else if (ql <= l && r <= qr) {
      return tree[i];
    } else {
      int m = l + r >> 1;
      int lc = i << 1, rc = (i << 1) + 1;
      return query(lc, l, m, ql, qr) + query(rc, m + 1, r, ql, qr);
    }
  }
};
template <class T>
struct DisjointRanges {
  struct Range {
    int l, r;
    T x;
    Range(int l, const pair<int, T>& p) : l(l), r(p.first), x(p.second) {}
  };
  map<int, pair<int, T>> s;
  vector<Range> update(int l, int r, T x) {
    vector<Range> bye;
    auto last = s.upper_bound(r);
    if (last != s.begin()) {
      auto it = prev(last);
      if (it->second.first > r) {
        last = s.emplace_hint(last, r + 1, it->second);
        it->second.first = r;
      }
    }
    auto first = s.lower_bound(l);
    if (first != s.begin()) {
      auto it = prev(first);
      if (it->second.first >= l) {
        bye.emplace_back(l, it->second);
        it->second.first = l - 1;
      }
    }
    while (first != last) {
      bye.emplace_back(first->first, first->second);
      first = s.erase(first);
    }
    s.emplace_hint(last, l, make_pair(r, x));
    return bye;
  }
};
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  RangeIncrement ri(n);
  DisjointRanges<int> dr;
  for (int i = 1; i <= n; i++) {
    dr.update(i, i, i);
  }
  while (m--) {
    int o, l, r, x;
    scanf("%d %d %d", &o, &l, &r);
    switch (o) {
      case 1: {
        scanf("%d", &x);
        auto v = dr.update(l, r, x);
        for (auto it : v) {
          ri.update(1, 1, n, it.l, it.r, abs(x - it.x));
        }
        break;
      }
      case 2: {
        printf("%lld\n", ri.query(1, 1, n, l, r));
        break;
      }
    }
  }
}
