#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

template <typename T, typename E>
struct lazy_segment_tree {
    using F = function<T(T, T)>;
    using G = function<T(T, E)>;
    using H = function<E(E, E)>;
    int n, height;
    vector<T> data;
    vector<E> lazy;
    F f;
    G g;
    H h;
    T ti;
    E ei;
    lazy_segment_tree(F f, G g, H h, T ti, E ei) : f(f), g(g), h(h), ti(ti), ei(ei) {}
    void init(int n_) {
        n = 1; height = 0;
        while (n < n_) n <<= 1, height++;
        data.assign(2*n, ti);
        lazy.assign(2*n, ei);
    }
    void build(const vector<T> &v) {
        int n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; ++i) data[n+i] = v[i];
        for (int i = n-1; i >= 1; --i) {
            data[i] = f(data[i<<1|0], data[i<<1|1]);
        }
    }
    inline T reflect(int i) {
        return lazy[i] == ei ? data[i] : g(data[i], lazy[i]);
    }
    inline void propagate(int i) {
        if (lazy[i] == ei) return;
        lazy[i<<1|0] = h(lazy[i<<1|0], lazy[i]);
        lazy[i<<1|1] = h(lazy[i<<1|1], lazy[i]);
        data[i] = reflect(i);
        lazy[i] = ei;
    }
    inline void thrust(int i) {
        for (int k = height; k >= 1; --k) propagate(i>>k);
    }
    inline void recalc(int i) {
        while (i > 1) {
            i >>= 1;
            data[i] = f(reflect(i<<1|0), reflect(i<<1|1));
        }
    }
    void update(int a, int b, E x) {
        a += n; b += n;
        thrust(a);
        thrust(b-1);
        int l = a, r = b;
        while (l < r) {
            if (l & 1) lazy[l] = h(lazy[l], x), l++;
            if (r & 1) --r, lazy[r] = h(lazy[r], x);
            l >>= 1; r >>= 1;
        }
        recalc(a);
        recalc(b-1);
    }
    void set(int i, T x) {
        i += n;
        thrust(i);
        data[i] = x;
        lazy[i] = ei;
        recalc(i);
    }
    T fold(int a, int b) {
        a += n; b += n;
        thrust(a);
        thrust(b-1);
        T resl = ti, resr = ti;
        int l = a, r = b;
        while (l < r) {
            if (l & 1) resl = f(resl, reflect(l++));
            if (r & 1) resr = f(reflect(--r), resr);
            l >>= 1; r >>= 1;
        }
        return f(resl, resr);
    }
    // min idx s.t. st <= idx && !check(fold(st, idx-1)) && check(fold(st, idx))
    template <typename C>
    int find(int st, C &check, T &acc, int i, int l, int r) {
        if (l+1 == r) {
            acc = f(acc, reflect(i));
            return check(acc) ? i-n : -1;
        }
        propagate(i);
        int m = (l+r) >> 1;
        if (m <= st) return find(st, check, acc, i<<1|1, m, r);
        if (st <= l && !check(f(acc, data[i]))) {
            acc = f(acc, data[i]);
            return -1;
        }
        int vl = find(st, check, acc, i<<1|0, l, m);
        if (vl != -1) return vl;
        return find(st, check, acc, i<<1|1, m, r);
    }
    template <typename C>
    int find(int st, C &check) {
        T acc = ti;
        return find(st, check, acc, 1, 0, n);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    auto f = [](P a, P b) { return P(a.fi + b.fi, a.se + b.se);};
    auto g = [](P a, int b) { return P(b * a.se, a.se);};
    auto h = [](int a, int b) { (void)a; return b;};
    lazy_segment_tree<P, int> seg(f, g, h, P(0, 0), 1001);
    seg.build(vector<P>(n, P(0, 1)));
    
    while (q--) {
        int com, s, t, x;
        cin >> com >> s >> t;
        if (com == 0) {
            cin >> x;
            seg.update(s, t+1, x);
        } else {
            cout << seg.fold(s, t+1).fi << endl;
        }
    }
}



Measured memory_bytes: 6756