#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 50;
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
int n, m;
void read(int &res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = (res << 3) + (res << 1) + (c ^ 48);
  while (c = getchar(), c > 47);
}
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
struct SegTree {
  struct node {
    int l, r, len, color, mid;
    long long sum, lazy;
  } my[maxn << 2];
  void build(int o, int l, int r) {
    my[o].l = l, my[o].r = r, my[o].len = (r - l + 1), my[o].mid = (l + r) / 2;
    my[o].sum = my[o].lazy = 0;
    my[o].color = -1;
    if (l == r) {
      my[o].color = l;
      return;
    }
    int mid = (l + r) / 2;
    build(o << 1, l, mid);
    build(o << 1 | 1, mid + 1, r);
  }
  inline void up(int o) {
    my[o].sum = my[o << 1].sum + my[o << 1 | 1].sum;
    if (my[o << 1].color == my[o << 1 | 1].color)
      my[o].color = my[o << 1].color;
    else
      my[o].color = -1;
  }
  void mix(int o, long long val, int col) {
    my[o].lazy += val;
    my[o].sum += 1LL * my[o].len * val;
    my[o].color = col;
  }
  void down(int o) {
    if (!my[o].lazy) return;
    mix(o << 1, my[o].lazy, my[o].color);
    mix(o << 1 | 1, my[o].lazy, my[o].color);
    my[o].lazy = 0;
  }
  void update(int o, int l, int r, int val) {
    if (my[o].l >= l && my[o].r <= r && ~my[o].color) {
      mix(o, abs(val - my[o].color), val);
      return;
    }
    int mid = my[o].mid;
    down(o);
    if (l <= mid) update(o << 1, l, r, val);
    if (r > mid) update(o << 1 | 1, l, r, val);
    up(o);
  }
  long long query(int o, int l, int r) {
    if (my[o].l >= l && my[o].r <= r) {
      return my[o].sum;
    }
    down(o);
    int mid = my[o].mid;
    long long ans = 0;
    if (l <= mid) ans += query(o << 1, l, r);
    if (r > mid) ans += query(o << 1 | 1, l, r);
    return ans;
  }
} seg;
int main() {
  read(n);
  read(m);
  seg.build(1, 1, n);
  while (m--) {
    int type, l, r, val;
    read(type);
    if (type == 1) {
      read(l);
      read(r);
      read(val);
      seg.update(1, l, r, val);
    } else {
      read(l);
      read(r);
      out(seg.query(1, l, r));
      puts("");
    }
  }
  return 0;
}
