func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& out, const tuple<T>& a) {     out <<  [  << get<0>(a) <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const tuple<T, U>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<  ] ;     return out;   }   template <class T, class U, class V>   ostream& operator<<(ostream& out, const tuple<T, U, V>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<     << get<2>(a) <<  ] ;     return out;   }   template <class T, class U, class V, class W>   ostream& operator<<(ostream& out, const tuple<T, U, V, W>& a) {     out <<  [  << get<0>(a) <<     << get<1>(a) <<     << get<2>(a) <<             << get<3>(a) <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const pair<T, U>& a) {     out <<  [  << a.first <<     << a.second <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const set<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const multiset<T>& a) {     out <<  [  ;     for (auto& it : a) out << it <<    ;     out <<  ] ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const map<T, U>& a) {     for (auto& it : a) out << it.first <<   ->   << it.second <<   |  ;     return out;   }   template <class T, class U>   ostream& operator<<(ostream& out, const multimap<T, U>& a) {     for (auto& it : a) out << it.first <<   ->   << it.second <<   |  ;     return out;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void r(){};   template <typename T, typename... Args>   void r(T& a, Args&... args) {     cin >> a;     r(args...);   }   void p() { cout <<   n ; };   template <typename T, typename... Args>   void p(T& a, Args&... args) {     cout << a <<    ;     p(args...);   }   template <class T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   template <class T>   T lcm(T a, T b) {     return ((a * b) / gcd(b % a, a));   }   template <class T1, class T2>   T1 binpow(T1 number, T2 power) {     T1 result = number;     while (power) {       if (power & 1) result = result * number;       number = number * number;       power /= 2;     }     return result;   }   long long n;   class Segtree {    public:     long long *tree, *lazy, *array, *color, *is_single;     Segtree(long long* arr, long long sz) {       array = new long long[sz];       lazy = new long long[4 * sz];       tree = new long long[4 * sz];       color = new long long[4 * sz];       is_single = new long long[4 * sz];       n = sz;       for (auto i = (0) - ((0) > (n)); i != (n) - ((0) > (n));            i += 1 - 2 * ((0) > (n)))         array[i] = arr[i];       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         tree[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         lazy[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         color[i] = 0;       for (auto i = (0) - ((0) > (4 * sz)); i != (4 * sz) - ((0) > (4 * sz));            i += 1 - 2 * ((0) > (4 * sz)))         is_single[i] = 0;       build();     }     void build(long long id = 1, long long l = 0, long long r = n) {       if (r - l < 2) {         tree[id] = 0;         color[id] = array[l];         is_single[id] = 1;         return;       }       auto mid = (l + r) / 2;       build(2 * id, l, mid);       build(2 * id + 1, mid, r);       tree[id] = tree[2 * id] + tree[2 * id + 1];       if (color[2 * id] == color[2 * id + 1] and color[2 * id] != 0)         is_single[id] = 1, color[id] = color[2 * id];       else         is_single[id] = 0, color[id] = 0;     }     void upd(long long id, long long l, long long r, long long x,              long long coloring) {       lazy[id] += x;       tree[id] += (r - l) * x;       if (coloring != 0) color[id] = coloring;     }     void shift(long long id, long long l, long long r) {       long long mid = (l + r) / 2;       upd(id * 2, l, mid, lazy[id], color[id]);       upd(id * 2 + 1, mid, r, lazy[id], color[id]);       lazy[id] = 0;     }     long long sum(long long x, long long y, long long id = 1, long long l = 0,                   long long r = n) {       if (l >= y or r <= x) return 0;       if (l >= x and r <= y) return tree[id];       shift(id, l, r);       auto mid = (l + r) / 2;       return sum(x, y, 2 * id, l, mid) + sum(x, y, 2 * id + 1, mid, r);     }     void range_update(long long x, long long y, long long coloring,                       long long id = 1, long long l = 0, long long r = n) {       auto mid = (l + r) / 2;       if (l >= y or r <= x) return;       if (x <= l and r <= y) {         if (is_single[id]) {           upd(id, l, r, abs(color[id] - coloring), coloring);         } else {           shift(id, l, r);           range_update(x, y, coloring, 2 * id, l, mid);           range_update(x, y, coloring, 2 * id + 1, mid, r);           tree[id] = tree[2 * id] + tree[2 * id + 1];         }         is_single[id] = 1;         color[id] = coloring;         return;       }       shift(id, l, r);       range_update(x, y, coloring, 2 * id, l, mid);       range_update(x, y, coloring, 2 * id + 1, mid, r);       tree[id] = tree[2 * id] + tree[2 * id + 1];       if (color[2 * id] == color[2 * id + 1] and color[2 * id] != 0)         is_single[id] = 1, color[id] = color[2 * id];       else         is_single[id] = 0, color[id] = 0;     }   };   long long m, arr[112345], types, lef, ri, x;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     r(n, m);     for (auto i = (0) - ((0) > (n)); i != (n) - ((0) > (n));          i += 1 - 2 * ((0) > (n)))       arr[i] = i + 1;     Segtree tree(arr, n);     for (auto i = (0) - ((0) > (m)); i != (m) - ((0) > (m));          i += 1 - 2 * ((0) > (m))) {       r(types);       if (types == 1) {         r(lef, ri, x);         tree.range_update(lef - 1, ri, x);       } else {         r(lef, ri);         auto sum = tree.sum(lef - 1, ri);         p(sum);       }     }   }   