#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


template<class Int> Int rng(Int a, Int b) {
  static mt19937 mt(chrono::steady_clock().now().time_since_epoch().count());
  assert(a < b);
  return uniform_int_distribution<Int>(a, b - 1)(mt);
}

namespace PersistentRandomizedBinaryTree {
  using T = struct { int sum, len; };
  T op(const T& lhs, const T& rhs) { return {lhs.sum + rhs.sum, lhs.len + rhs.len}; }
  T op(const T& lhs, const T& mhs, const T& rhs) { return op(op(lhs, mhs), rhs); }
  constexpr T e = {0, 0};

  using U = int;
  constexpr U id = 1001;
  T ap(const U& f, const T& x) { return f != id ? T{f * x.len, x.len} : x; }
  U cp(const U& g, const U& f) { return g != id ? g : f; }

  struct Node;
  using Tree = shared_ptr<const Node>;
  struct Node {
    int sz = 0;
    T val = e, acc = e;
    U laz = id;
    bool rev = false;
    Tree cl = nullptr, cr = nullptr;
    Node() {} // nil
    Node(const T& val); // leaf
    Node(const T& val, const T& acc, const U& laz, bool rev, Tree cl, Tree cr) :
      sz(cl->sz + 1 + cr->sz), val(val), acc(acc), laz(laz), rev(rev), cl(cl), cr(cr) {}
    Node(Tree t, Tree cl, Tree cr) :
      sz(cl->sz + 1 + cr->sz), val(t->val), acc(op(cl->acc, t->val, cr->acc)), laz(t->laz), rev(t->rev), cl(cl), cr(cr) {}
  };
  Tree nil = make_shared<Node>();
  Node::Node(const T& val) : sz(1), val(val), acc(val), cl(nil), cr(nil) {}

  Tree act(Tree t, const U& f) {
    if (t == nil) return t;
    return make_shared<Node>(ap(f, t->val), ap(f, t->acc), cp(f, t->laz), t->rev, t->cl, t->cr);
  }
  Tree reverse(Tree t) {
    if (t == nil) return t;
    return make_shared<Node>(t->val, t->acc, t->laz, !t->rev, t->cr, t->cl);
  }
  Tree push(Tree t) {
    if (t->laz == id and !t->rev) return t;
    Tree cl = t->laz != id ? act(t->cl, t->laz) : t->cl;
    Tree cr = t->laz != id ? act(t->cr, t->laz) : t->cr;
    if (t->rev) {
      cl = reverse(cl);
      cr = reverse(cr);
    }
    return make_shared<Node>(t->val, t->acc, id, false, cl, cr);
  }

  template<class Itr> Tree build(Itr first, Itr last) {
    int n = distance(first, last);
    if (n == 0) return nil;
    Itr middle = next(first, n / 2);
    Tree cl = build(first, middle);
    Tree cr = build(next(middle), last);
    return make_shared<Node>(*middle, op(cl->acc, *middle, cr->acc), id, false, cl, cr);
  }
  template<class Itr> Itr dump(Tree t, Itr res) {
    if (t == nil) return res;
    push(t);
    res = dump(t->cl, res);
    *res++ = t->val;
    res = dump(t->cr, res);
    return res;
  }
  Tree rebuild(Tree t) {
    V<T> v(t->sz);
    dump(t, begin(v));
    return build(begin(v), end(v));
  }

  Tree merge(Tree tl, Tree tr) {
    if (tr == nil) return tl;
    if (tl == nil) return tr;
    if (rng(0, tl->sz + tr->sz) < tl->sz) {
      tl = push(tl);
      return make_shared<Node>(tl, tl->cl, merge(tl->cr, tr));
    } else {
      tr = push(tr);
      return make_shared<Node>(tr, merge(tl, tr->cl), tr->cr);
    }
  }
  Tree merge(Tree tl, Tree tm, Tree tr) {
    return merge(merge(tl, tm), tr);
  }
  pair<Tree, Tree> split(Tree t, int i) {
    if (t == nil) return {nil, nil};
    t = push(t);
    if (i <= t->cl->sz) {
      Tree tl, cl;
      tie(tl, cl) = split(t->cl, i);
      return {tl, make_shared<Node>(t, cl, t->cr)};
    } else {
      Tree cr, tr;
      tie(cr, tr) = split(t->cr, i - t->cl->sz - 1);
      return {make_shared<Node>(t, t->cl, cr), tr};
    }
  }
  tuple<Tree, Tree, Tree> split(Tree t, int l, int r) {
    Tree tl, tm, tr;
    tie(tl, tr) = split(t, r);
    tie(tl, tm) = split(tl, l);
    return make_tuple(tl, tm, tr);
  }

  Tree insert(Tree t, int i, const T& val) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    return merge(tl, make_shared<Node>(val), tr);
  }
  Tree erase(Tree t, int i) {
    Tree tl, tm, tr;
    tie(tl, tm, tr) = split(t, i, i + 1);
    return merge(tl, tr);
  }

  T get_val(Tree t, int i) {
    if (t == nil) return e;
    if (i == t->cl->sz) return t->val;
    t = push(t);
    if (i < t->cl->sz) return get_val(t->cl, i);
    else return get_val(t->cr, i - t->cl->sz - 1);
  }
  Tree set_val(Tree t, int i, const T& val) {
    if (t == nil) return t;
    t = push(t);
    if (i == t->cl->sz) return make_shared<Node>(val, op(t->cl->acc, val, t->cr->acc), t->laz, t->rev, t->cl, t->cr);
    if (i < t->cl->sz) {
      Tree cl = set_val(t->cl, i, val);
      return make_shared<Node>(t, cl, t->cr);
    } else {
      Tree cr = set_val(t->cr, i - t->cl->sz - 1, val);
      return make_shared<Node>(t, t->cl, cr);
    }
  }

  T acc(Tree t, int l, int r) {
    if (t == nil or l <= 0 and t->sz <= r) return t->acc;
    t = push(t);
    T resl = l < t->cl->sz ? acc(t->cl, l, r) : e;
    T resr = t->cl->sz + 1 < r ? acc(t->cr, l - t->cl->sz - 1, r - t->cl->sz - 1) : e;
    T resm = l <= t->cl->sz and t->cl->sz < r ? t->val : e;
    return op(resl, resm, resr);
  }
  Tree act(Tree t, int l, int r, const U& f) {
    if (t == nil or l <= 0 and t->sz <= r) return act(t, f);
    t = push(t);
    Tree cl = l < t->cl->sz ? act(t->cl, l, r, f) : t->cl;
    Tree cr = t->cl->sz + 1 < r ? act(t->cr, l - t->cl->sz - 1, r - t->cl->sz - 1, f) : t->cr;
    T val = l <= t->cl->sz and t->cl->sz < r ? ap(f, t->val) : t->val;
    T acc = op(cl->acc, val, cr->acc);
    return make_shared<Node>(val, acc, t->laz, t->rev, cl, cr);
  }
  Tree reverse(Tree t, int l, int r) {
    Tree tl, tm, tr;
    tie(tl, tm, tr) = split(t, l, r);
    tm = reverse(tm);
    return merge(tl, tm, tr);
  }
}

using namespace PersistentRandomizedBinaryTree;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  V<T> a(n, {0, 1});
  Tree t = build(begin(a), end(a));
  while (q--) {
    int type; cin >> type;
    if (type == 0) {
      int l, r, x; cin >> l >> r >> x, ++r;
      t = act(t, l, r, x);
    } else {
      int l, r; cin >> l >> r, ++r;
      cout << acc(t, l, r).sum << '\n';
    }
  }
}


Measured memory_bytes: 13072