#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return w ? -x : x;
}
const int N = 500010;
struct seg_tree {
  long long lazy, s, flag;
} t[N << 2];
int n, m;
void build(int root, int l, int r) {
  if (l == r) {
    t[root].flag = l;
    return;
  }
  int mid = l + r >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
}
long long query(int root, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return t[root].s;
  int mid = l + r >> 1;
  long long ans = 0;
  if (ll <= mid) ans += query(root << 1, l, mid, ll, rr);
  if (rr > mid) ans += query(root << 1 | 1, mid + 1, r, ll, rr);
  return ans + max(0, min(r, rr) - max(l, ll) + 1) * t[root].lazy;
}
void empty(int root, int l, int r, int s) {
  if (t[root].flag) {
    t[root].lazy += abs(t[root].flag - s);
    t[root].s += abs(t[root].flag - s) * (r - l + 1);
    t[root].flag = 0;
    return;
  }
  if (l == r) return;
  int mid = l + r >> 1;
  empty(root << 1, l, mid, s);
  empty(root << 1 | 1, mid + 1, r, s);
  t[root].s = t[root << 1].s + t[root << 1 | 1].s + t[root].lazy * (r - l + 1);
}
void pushdown(int root) {
  if (!t[root].flag) return;
  t[root << 1].flag = t[root << 1 | 1].flag = t[root].flag;
  t[root].flag = 0;
}
void change(int root, int l, int r, int ll, int rr, int s) {
  if (ll <= l && r <= rr) {
    empty(root, l, r, s);
    t[root].flag = s;
    return;
  }
  int mid = l + r >> 1;
  pushdown(root);
  if (ll <= mid) change(root << 1, l, mid, ll, rr, s);
  if (rr > mid) change(root << 1 | 1, mid + 1, r, ll, rr, s);
  t[root].s = t[root << 1].s + t[root << 1 | 1].s + t[root].lazy * (r - l + 1);
}
int main(int argc, char const *argv[]) {
  n = read(), m = read();
  build(1, 1, n);
  while (m--) {
    int type = read();
    if (type == 1) {
      int l = read(), r = read(), x = read();
      change(1, 1, n, l, r, x);
    } else {
      int l = read(), r = read();
      printf("%lld\n", query(1, 1, n, l, r));
    }
  }
  return 0;
}
