#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int N = (1 << 18) + 10;
int n;
int m;
long long tree[N];
long long add[N];
int same[N];
int col[N];
int build(int x, int l, int r) {
  tree[x] = 0;
  same[x] = 0;
  col[x] = 0;
  add[x] = 0;
  if (l == r) {
    same[x] = 1;
    col[x] = l + 1;
    return 0;
  }
  int s = (l + r) / 2;
  build(x * 2 + 1, l, s);
  build(x * 2 + 2, s + 1, r);
  return 0;
}
int push(int x, int l, int r) {
  if (add[x]) {
    tree[x] += (long long)(r - l + 1) * add[x];
    if (l != r) {
      add[x * 2 + 1] += add[x];
      add[x * 2 + 2] += add[x];
    }
    add[x] = 0;
  }
  if (same[x]) {
    if (l != r) {
      same[x * 2 + 1] = same[x * 2 + 2] = 1;
      col[x * 2 + 1] = col[x * 2 + 2] = col[x];
    }
  }
  return 0;
}
long long upd(int x, int l, int r, int lc, int rc, int y) {
  push(x, l, r);
  if (r < lc || l > rc) return tree[x];
  if (l >= lc && r <= rc) {
    if (same[x]) {
      add[x] += abs(col[x] - y);
      col[x] = y;
      push(x, l, r);
      return tree[x];
    } else {
      same[x] = 1;
      col[x] = y;
    }
  } else {
    if (same[x] && col[x] != y) {
      same[x] = 0;
      col[x] = 0;
    }
  }
  int s = (l + r) / 2;
  return tree[x] = upd(x * 2 + 1, l, s, lc, rc, y) +
                   upd(x * 2 + 2, s + 1, r, lc, rc, y);
}
long long get(int x, int l, int r, int lc, int rc) {
  push(x, l, r);
  if (r < lc || l > rc) return 0;
  if (l >= lc && r <= rc) return tree[x];
  int s = (l + r) / 2;
  return get(x * 2 + 1, l, s, lc, rc) + get(x * 2 + 2, s + 1, r, lc, rc);
}
int main() {
  scanf("%d%d", &n, &m);
  build(0, 0, n - 1);
  for (int i = 0; i < m; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      l--;
      r--;
      upd(0, 0, n - 1, l, r, x);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      l--;
      r--;
      printf("%I64d\n", get(0, 0, n - 1, l, r));
    }
  }
  return 0;
}
