func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, len[400], cnt, Block, pos[100010];   long long c[100010], sum[400], v[100010], cov[400], dlt[400];   bool mak[400];   void BuildBlocks() {     int tail;     for (int i = 1; i <= n; i = tail + 1) {       tail = min(i + Block - 1, n);       ++cnt;       len[cnt] = tail;       for (int j = i; j <= tail; j++) pos[j] = cnt;     }   }   long long Abs(long long x) { return (x < 0) ? -x : x; }   void work(int x, int y, long long k) {     int now = pos[x];     long long delta;     for (int i = x; i <= y; i++) {       delta = Abs(v[i] - k);       v[i] = k;       c[i] += delta;       sum[now] += delta;     }   }   void pushdown(int now) {     if (cov[now] != 0) {       for (int i = len[now - 1] + 1; i <= len[now]; i++) v[i] = cov[now];       cov[now] = 0;     }   }   void Change(int x, int y, long long k) {     int px, py, H, T;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) {       pushdown(px);       work(x, y, k);       mak[px] = false;       return;     }     if (x == len[px - 1] + 1)       --H;     else {       pushdown(px);       mak[px] = false;       work(x, len[px], k);     }     if (y == len[py])       ++T;     else {       pushdown(py);       mak[py] = false;       work(len[py - 1] + 1, y, k);     }     if (H > T) return;     for (int i = H; i <= T; i++)       if (mak[i] == false) {         work(len[i - 1] + 1, len[i], k);         mak[i] = true;       } else {         if (cov[i] == 0) cov[i] = v[len[i]];         sum[i] += (long long)(len[i] - len[i - 1]) * Abs(k - cov[i]);         dlt[i] += Abs(k - cov[i]);         cov[i] = k;       }   }   long long count(int x, int y) {     long long ans = 0;     int now = pos[x];     for (int i = x; i <= y; i++) ans += c[i] + dlt[now];     return ans;   }   long long Query(int x, int y) {     int px, py, H, T;     long long ans = 0;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) return count(x, y);     if (x == len[px - 1] + 1)       --H;     else       ans += count(x, len[px]);     if (y == len[py])       ++T;     else       ans += count(len[py - 1] + 1, y);     for (int i = H; i <= T; i++) ans += sum[i];     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) v[i] = i;     Block = ceil(sqrt(n));     BuildBlocks();     for (int i = 1; i <= m; i++) {       int opt, x, y, k;       scanf( %d%d%d , &opt, &x, &y);       if (opt == 1) {         scanf( %d , &k);         Change(x, y, k);       } else         printf( %I64d n , Query(x, y));     }     return 0;   }   