func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200010;   struct tree {     int lt, rt;     long long sumdis, sum, cnt;   } a[N * 4];   int c[N], b[N], tmp[N], cnt, bb[N];   int find(int x) {     int lt = 1, rt = cnt, mid;     while (lt <= rt) {       mid = (lt + rt) / 2;       if (c[mid] == x) return mid;       if (c[mid] > x)         rt = mid - 1;       else         lt = mid + 1;     }   }   int find_lt(int x) {     int lt = 1, rt = cnt, mid, ans = -1;     while (lt <= rt) {       mid = (lt + rt) / 2;       if (c[mid] >= x)         ans = mid, rt = mid - 1;       else         lt = mid + 1;     }     return ans;   }   int find_rt(int x) {     int lt = 1, rt = cnt, mid, ans = -1;     while (lt <= rt) {       mid = (lt + rt) / 2;       if (c[mid] <= x)         ans = mid, lt = mid + 1;       else         rt = mid - 1;     }     return ans;   }   void init(int lt, int rt, int step) {     a[step].lt = lt;     a[step].rt = rt;     a[step].sumdis = a[step].sum = a[step].cnt = 0;     if (lt == rt) return;     int mid = (lt + rt) / 2;     init(lt, mid, 2 * step);     init(mid + 1, rt, 2 * step + 1);   }   void insert(int pos, int step, int val) {     if (a[step].lt == a[step].rt) {       a[step].sumdis += c[pos] * val;       a[step].sum = 0;       a[step].cnt += val;       return;     }     if (pos <= a[2 * step].rt)       insert(pos, 2 * step, val);     else       insert(pos, 2 * step + 1, val);     a[step].sumdis = a[2 * step].sumdis + a[2 * step + 1].sumdis;     a[step].cnt = a[2 * step].cnt + a[2 * step + 1].cnt;     a[step].sum = a[2 * step].sum + a[2 * step + 1].sum;     a[step].sum += a[2 * step + 1].sumdis * a[step * 2].cnt -                    a[2 * step].sumdis * a[step * 2 + 1].cnt;   }   void query(int lt, int rt, int step, long long &sumdis, long long &ccnt,              long long &sum) {     if (a[step].lt == lt && a[step].rt == rt) {       sumdis = a[step].sumdis;       ccnt = a[step].cnt;       sum = a[step].sum;       return;     }     if (rt <= a[2 * step].rt)       query(lt, rt, 2 * step, sumdis, ccnt, sum);     else if (lt > a[2 * step].rt)       query(lt, rt, 2 * step + 1, sumdis, ccnt, sum);     else {       long long sumdis1, sumdis2, cnt1, cnt2, sum1, sum2;       query(lt, a[2 * step].rt, 2 * step, sumdis1, cnt1, sum1);       query(a[2 * step + 1].lt, rt, 2 * step + 1, sumdis2, cnt2, sum2);       sum = sum1 + sum2;       sum += sumdis2 * cnt1 - sumdis1 * cnt2;       ccnt = cnt1 + cnt2;       sumdis = sumdis1 + sumdis2;     }   }   struct point {     int x, y, z;     void read() { scanf( %d%d%d , &x, &y, &z); }   } pt[N];   int main() {     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       tmp[i] = bb[i] = b[i];     }     int tot = n;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       pt[i].read();       if (pt[i].x == 1) {         b[pt[i].y] += pt[i].z;         tmp[++tot] = b[pt[i].y];       }     }     sort(tmp + 1, tmp + tot + 1);     cnt = 1;     c[1] = tmp[1];     for (int i = 2; i <= tot; i++)       if (tmp[i] != c[cnt]) c[++cnt] = tmp[i];     init(1, cnt, 1);     int x, y, z;     for (int i = 1; i <= n; i++) insert(find(bb[i]), 1, 1);     for (int i = 1; i <= m; i++) {       x = pt[i].x, y = pt[i].y, z = pt[i].z;       if (x == 1) {         insert(find(bb[y]), 1, -1);         bb[y] += z;         insert(find(bb[y]), 1, 1);       } else {         long long t1 = 0, t2 = 0, t3 = 0;         y = find_lt(y);         z = find_rt(z);         if (y == -1 || z == -1 || y > z)           printf( 0 n );         else {           query(y, z, 1, t1, t2, t3);           printf( %I64d n , t3);         }       }     }     return 0;   }   