#include <bits/stdc++.h>
using namespace std;
int n, m;
int t, l, r, x;
int color[4 * 100002];
long long sum[4 * 100002], delta[4 * 100002];
void init(int root, int l, int r) {
  if (l + 1 == r) {
    color[root] = l;
    return;
  }
  init(root * 2, l, (l + r) / 2);
  init(root * 2 + 1, (l + r) / 2, r);
}
void clear(int root, int a, int b, int x) {
  if (color[root]) {
    long long diff = abs(color[root] - x);
    sum[root] += diff * (b - a);
    delta[root] += diff;
    color[root] = 0;
  } else {
    clear(root * 2, a, (a + b) / 2, x);
    clear(root * 2 + 1, (a + b) / 2, b, x);
    sum[root] = sum[root * 2] + sum[root * 2 + 1] + delta[root] * (b - a);
  }
}
void paint(int root, int a, int b, int l, int r, int x) {
  if (l <= a && r >= b) {
    clear(root, a, b, x);
    color[root] = x;
    return;
  }
  if (color[root]) {
    color[root * 2] = color[root * 2 + 1] = color[root];
  }
  color[root] = 0;
  if (l >= (a + b) / 2)
    paint(root * 2 + 1, (a + b) / 2, b, l, r, x);
  else if (r <= (a + b) / 2)
    paint(root * 2, a, (a + b) / 2, l, r, x);
  else
    paint(root * 2, a, (a + b) / 2, l, r, x),
        paint(root * 2 + 1, (a + b) / 2, b, l, r, x);
  sum[root] = sum[root * 2] + sum[root * 2 + 1] + delta[root] * (b - a);
}
long long getSum(int root, int a, int b, int l, int r) {
  if (l <= a && r >= b) return sum[root];
  long long d = delta[root] * (min(b, r) - max(l, a));
  if (l >= (a + b) / 2)
    return d + getSum(root * 2 + 1, (a + b) / 2, b, l, r);
  else if (r <= (a + b) / 2)
    return getSum(root * 2, a, (a + b) / 2, l, r) + d;
  else
    return d + getSum(root * 2, a, (a + b) / 2, l, r) +
           getSum(root * 2 + 1, (a + b) / 2, b, l, r);
}
int main() {
  scanf("%d%d", &n, &m);
  init(1, 1, n + 1);
  while (m--) {
    scanf("%d%d%d", &t, &l, &r);
    r++;
    if (t == 1) {
      scanf("%d", &x);
      paint(1, 1, n + 1, l, r, x);
    } else {
      printf("%I64d\n", getSum(1, 1, n + 1, l, r));
    }
  }
  return 0;
}
