#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m, a[maxn], ql[maxn], qr[maxn], ans, top;
struct node {
  int sum, maxs, maxl, maxr, mins, minl, minr, pmaxs, pmaxr, pmins, pminr,
      smaxs, smaxl, smins, sminl;
  bool tag;
} t[maxn << 2];
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < 48 || c > 57) f = c == '-' ? -1 : 1, c = getchar();
  while (c >= 48 && c <= 57) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
void swap(int &x, int &y) {
  int t = x;
  x = y, y = t;
}
void re(int &x) { x = -x; }
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
node operator+(const node &a, const node &b) {
  node c;
  c.tag = 0;
  c.sum = a.sum + b.sum;
  if (a.sum + b.pmaxs > a.pmaxs) {
    c.pmaxs = a.sum + b.pmaxs;
    c.pmaxr = b.pmaxr;
  } else {
    c.pmaxs = a.pmaxs;
    c.pmaxr = a.pmaxr;
  }
  if (a.sum + b.pmins < a.pmins) {
    c.pmins = a.sum + b.pmins;
    c.pminr = b.pminr;
  } else {
    c.pmins = a.pmins;
    c.pminr = a.pminr;
  }
  if (a.smaxs + b.sum > b.smaxs) {
    c.smaxs = a.smaxs + b.sum;
    c.smaxl = a.smaxl;
  } else {
    c.smaxs = b.smaxs;
    c.smaxl = b.smaxl;
  }
  if (a.smins + b.sum < b.smins) {
    c.smins = a.smins + b.sum;
    c.sminl = a.sminl;
  } else {
    c.smins = b.smins;
    c.sminl = b.sminl;
  }
  if (max(a.maxs, b.maxs) > a.smaxs + b.pmaxs) {
    if (a.maxs > b.maxs) {
      c.maxs = a.maxs;
      c.maxl = a.maxl;
      c.maxr = a.maxr;
    } else {
      c.maxs = b.maxs;
      c.maxl = b.maxl;
      c.maxr = b.maxr;
    }
  } else {
    c.maxs = a.smaxs + b.pmaxs;
    c.maxl = a.smaxl;
    c.maxr = b.pmaxr;
  }
  if (min(a.mins, b.mins) < a.smins + b.pmins) {
    if (a.mins < b.mins) {
      c.mins = a.mins;
      c.minl = a.minl;
      c.minr = a.minr;
    } else {
      c.mins = b.mins;
      c.minl = b.minl;
      c.minr = b.minr;
    }
  } else {
    c.mins = a.smins + b.pmins;
    c.minl = a.sminl;
    c.minr = b.pminr;
  }
  return c;
}
void rev(int o) {
  re((t[o]).sum);
  re((t[o]).maxs), re((t[o]).mins);
  re((t[o]).pmaxs), re((t[o]).pmins);
  re((t[o]).smaxs), re((t[o]).smins);
  swap((t[o]).maxs, (t[o]).mins), swap((t[o]).maxl, (t[o]).minl),
      swap((t[o]).maxr, (t[o]).minr);
  swap((t[o]).pmaxs, (t[o]).pmins), swap((t[o]).pmaxr, (t[o]).pminr);
  swap((t[o]).smaxs, (t[o]).smins), swap((t[o]).smaxl, (t[o]).sminl);
  (t[o]).tag ^= 1;
}
void pushup(int o) {
  bool tg = (t[o]).tag;
  (t[o]) = t[(o << 1)] + t[((o << 1) | 1)];
  (t[o]).tag = tg;
}
void pushdown(int o) {
  if ((t[o]).tag) {
    rev((o << 1)), rev(((o << 1) | 1));
    (t[o]).tag = 0;
  }
}
void modify(int o, int v) {
  (t[o]).sum = (t[o]).maxs = (t[o]).mins = (t[o]).pmaxs = (t[o]).pmins =
      (t[o]).smaxs = (t[o]).smins = v;
}
void build(int o, int l, int r) {
  if (l == r) {
    modify(o, a[l]);
    (t[o]).maxl = (t[o]).maxr = (t[o]).minl = (t[o]).minr = (t[o]).pmaxr =
        (t[o]).pminr = (t[o]).smaxl = (t[o]).sminl = l;
    return;
  }
  build((o << 1), l, ((l + r) >> 1));
  build(((o << 1) | 1), ((l + r) >> 1) + 1, r);
  pushup(o);
}
void update_point(int o, int l, int r, int x, int v) {
  if (l == r) {
    modify(o, v);
    (t[o]).tag = 0;
    return;
  }
  pushdown(o);
  if (x <= ((l + r) >> 1))
    update_point((o << 1), l, ((l + r) >> 1), x, v);
  else
    update_point(((o << 1) | 1), ((l + r) >> 1) + 1, r, x, v);
  pushup(o);
}
void update(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) {
    rev(o);
    return;
  }
  pushdown(o);
  if (y <= ((l + r) >> 1))
    update((o << 1), l, ((l + r) >> 1), x, y);
  else if (((l + r) >> 1) + 1 <= x)
    update(((o << 1) | 1), ((l + r) >> 1) + 1, r, x, y);
  else
    update((o << 1), l, ((l + r) >> 1), x, ((l + r) >> 1)),
        update(((o << 1) | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, y);
  pushup(o);
}
node query(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) return (t[o]);
  pushdown(o);
  if (y <= ((l + r) >> 1))
    return query((o << 1), l, ((l + r) >> 1), x, y);
  else if (((l + r) >> 1) + 1 <= x)
    return query(((o << 1) | 1), ((l + r) >> 1) + 1, r, x, y);
  else
    return query((o << 1), l, ((l + r) >> 1), x, ((l + r) >> 1)) +
           query(((o << 1) | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, y);
}
int main() {
  int i, op, l, r, k;
  node tmp;
  n = read();
  for (i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  m = read();
  while (m--) {
    op = read();
    if (op) {
      top = ans = 0;
      l = read(), r = read(), k = read();
      while (k--) {
        tmp = query(1, 1, n, l, r);
        if (tmp.maxs < 0) break;
        ans += tmp.maxs;
        ql[++top] = tmp.maxl, qr[top] = tmp.maxr;
        update(1, 1, n, tmp.maxl, tmp.maxr);
      }
      for (i = top; i >= 1; i--) update(1, 1, n, ql[i], qr[i]);
      printf("%d\n", ans);
    } else {
      i = read(), k = read();
      update_point(1, 1, n, i, k);
    }
  }
  return 0;
}
