#include <bits/stdc++.h>
const int N = 1e5 + 7;
using namespace std;
struct node {
  int a, b, lazy;
  long long sum, cnt;
  node *l, *r;
} tree[N + N];
int pos;
node *build(int a, int b) {
  node *root = &tree[++pos];
  root->a = a;
  root->b = b;
  if (root->a == root->b) {
    root->lazy = root->a;
    return root;
  }
  root->lazy = -1;
  int mid = (a + b) >> 1;
  root->l = build(a, mid);
  root->r = build(mid + 1, b);
  return root;
}
void fix(node *root, int x) {
  root->cnt += abs(root->lazy - x);
  root->sum += abs(root->lazy - x) * (root->b - root->a + 1LL);
  root->lazy = x;
}
void spread(node *root) {
  root->l->cnt += root->cnt;
  root->r->cnt += root->cnt;
  root->l->sum += root->cnt * (root->l->b - root->l->a + 1LL);
  root->r->sum += root->cnt * (root->r->b - root->r->a + 1LL);
  root->cnt = 0;
  root->l->lazy = root->r->lazy = root->lazy;
  root->lazy = -1;
}
void mix(node *root) {
  root->sum = root->l->sum + root->r->sum;
  if (root->l->lazy == root->r->lazy) root->lazy = root->l->lazy;
}
void insert(node *root, int a, int b, int x) {
  if (root->lazy >= 0 && root->a >= a && root->b <= b) {
    fix(root, x);
    return;
  }
  int mid = (root->a + root->b) >> 1;
  if (root->lazy != -1) spread(root);
  if (a <= mid) insert(root->l, a, b, x);
  if (b > mid) insert(root->r, a, b, x);
  mix(root);
}
long long find(node *root, int a, int b) {
  if (root->a >= a && root->b <= b) return root->sum;
  int mid = (root->a + root->b) >> 1;
  if (root->lazy != -1) spread(root);
  long long ret = 0;
  if (a <= mid) ret += find(root->l, a, b);
  if (b > mid) ret += find(root->r, a, b);
  mix(root);
  return ret;
}
void check() {
  for (int i = 1; i <= pos; i++) {
    node *root = &tree[i];
    printf("L %d R %d : \n sum %I64d lazy %d cnt %I64d\n", root->a, root->b,
           root->sum, root->lazy, root->cnt);
  }
  puts("-----------\n\n");
}
int main() {
  int n, m, op, l, r, x;
  scanf("%d%d", &n, &m);
  node *root = build(1, n);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      scanf("%d", &x);
      insert(root, l, r, x);
    } else
      printf("%I64d\n", find(root, l, r));
  }
  return 0;
}
