func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Block {     long long l, r, c;     Block(long long l, long long r, long long c) : l(l), r(r), c(c) {}   };   bool operator<(Block a, Block b) {     if (a.l != b.l) return a.l < b.l;     if (a.r != b.r) return a.r < b.r;     return a.c < b.c;   }   const int maxn = 1000000 + 10;   long long tr_a[maxn], tr_b[maxn];   void add(long long tr[maxn], long long at, long long what) {     for (++at; at < maxn; at += -at & at) tr[at] += what;   }   void modify(long long l, long long r, long long c) {     add(tr_a, l, c);     add(tr_b, l, (l - 1) * c);     add(tr_a, r + 1, -c);     add(tr_b, r + 1, -r * c);   }   long long sum(long long tr[maxn], long long at) {     long long s = 0;     for (++at; at > 0; at -= -at & at) s += tr[at];     return s;   }   long long query(long long l, long long r) {     long long sr = r * sum(tr_a, r) - sum(tr_b, r);     long long sl = (l - 1) * sum(tr_a, l - 1) - sum(tr_b, l - 1);     return sr - sl;   }   int main() {     ios_base::sync_with_stdio(false);     memset((tr_a), (0), sizeof(tr_a)), memset((tr_b), (0), sizeof(tr_b));     int n, q;     cin >> n >> q;     set<Block> blocks;     for (int _n(n + 1), i(1); i < _n; i++) blocks.insert(Block(i, i, i));     for (int _n(q), _(0); _ < _n; _++) {       long long op, l, r, x;       cin >> op >> l >> r;       if (op == 1) {         cin >> x;         auto it = blocks.upper_bound(Block(l, 1011111111, 1011111111));         --it;         while (it != blocks.end()) {           if (it->l > r) break;           Block tmp = *it;           modify(max(l, tmp.l), min(r, tmp.r), labs(tmp.c - x));           if (tmp.l < l) {             blocks.insert(Block(tmp.l, l - 1, tmp.c));           }           if (tmp.r > r) {             blocks.insert(Block(r + 1, tmp.r, tmp.c));           }           ++it;           blocks.erase(blocks.find(tmp));         }         blocks.insert(Block(l, r, x));       } else {         long long ans = query(l, r);         cout << ans << endl;       }     }     return 0;   }   