#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
const long long oo = 1000;
int n, query, u, v, val, type;
long long zip[N * 4], zipsum[N * 4], IT[N * 4];
void build(int i, int l, int r) {
  if (l > r) return;
  if (l == r) {
    zip[i] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(i << 1, l, mid);
  build((i << 1) + 1, mid + 1, r);
}
void update(int i, int l, int r, int u, int v, int val) {
  if (l > r || l > v || r < u) return;
  if (l >= u && r <= v && zip[i]) {
    zipsum[i] += abs(val - zip[i]);
    zip[i] = val;
    return;
  }
  int mid = (l + r) >> 1;
  int i1 = i << 1, i2 = i1 + 1;
  if (zip[i]) {
    zipsum[i1] += zipsum[i];
    zipsum[i2] += zipsum[i];
    zip[i1] = zip[i2] = zip[i];
    zipsum[i] = zip[i] = 0;
  }
  update(i1, l, mid, u, v, val);
  update(i2, mid + 1, r, u, v, val);
  IT[i] = IT[i1] + IT[i2] + zipsum[i1] * (mid - l + 1) + zipsum[i2] * (r - mid);
  if (zip[i1] && zip[i2] && (zip[i1] == zip[i2])) zip[i] = zip[i1];
}
long long get(int i, int l, int r, int u, int v) {
  if (l > r || l > v || r < u) return 0ll;
  if (l >= u && r <= v) return (IT[i] + zipsum[i] * (r - l + 1));
  int mid = (l + r) >> 1;
  int i1 = i << 1, i2 = i1 + 1;
  if (zip[i]) {
    zipsum[i1] += zipsum[i];
    zipsum[i2] += zipsum[i];
    zip[i1] = zip[i2] = zip[i];
    zipsum[i] = zip[i] = 0;
  }
  long long ret = get(i1, l, mid, u, v) + get(i2, mid + 1, r, u, v);
  IT[i] = IT[i1] + IT[i2] + zipsum[i1] * (mid - l + 1) + zipsum[i2] * (r - mid);
  if (zip[i1] && zip[i2] && (zip[i1] == zip[i2])) zip[i] = zip[i1];
  return ret;
}
int main() {
  scanf("%d %d", &n, &query);
  build(1, 1, n);
  while (query--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d %d", &u, &v, &val);
      update(1, 1, n, u, v, val);
    } else {
      scanf("%d %d", &u, &v);
      long long ans = get(1, 1, n, u, v);
      printf("%I64d\n", ans);
    }
  }
}
