#include <cstdio>
#include <algorithm>

const int INF = 1 << 30;
const int N = 1 << 19;
int mi[2 * N], ma[2 * N];
long long sum[2 * N];


void setv(int x, int y) {
  x += N;
  mi[x] = y;
  ma[x] = y;
  sum[x] = y;
  while (x > 1) {
    x >>= 1;
    mi[x] = std::min(mi[x * 2], mi[x * 2 + 1]);
    ma[x] = std::max(ma[x * 2], ma[x * 2 + 1]);
    sum[x] = sum[2 * x] + sum[2 * x + 1];
  }
}

long long gsum(int l, int r) {
  --r;
  l += N;
  r += N;
  long long ret = 0;
  while (l <= r) {
    if ((l & 1) == 1) {
      ret += sum[l++];
    }
    if ((r & 1) == 0) {
      ret += sum[r--];
    }
    l >>= 1;
    r >>= 1;
  }
  return ret;
}

int gmin(int l, int r) {
  --r;
  l += N;
  r += N;
  int ret = INF;
  while (l <= r) {
    if ((l & 1) == 1) {
      if (ret > mi[l]) ret = mi[l];
      ++l;
    }
    if ((r & 1) == 0) {
      if (ret > mi[r]) ret = mi[r];
      --r;
    }
    l >>= 1;
    r >>= 1;
  }
  return ret;
}

int gmax(int l, int r) {
  --r;
  l += N;
  r += N;
  int ret = -INF;
  while (l <= r) {
    if ((l & 1) == 1) {
      ret = std::max(ret, ma[l++]);
    }
    if ((r & 1) == 0) {
      ret = std::max(ret, ma[r--]);
    }
    l >>= 1;
    r >>= 1;
  }
  return ret;
}

int main() {
  freopen("hel.in", "r", stdin);
  freopen("hel.out", "w", stdout);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    setv(i, x);
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int c = getchar();
    while (c <= 32) c = getchar();
    int op = c;
    while (c > 32) c = getchar();
    if (op == 'a') {
      int x, y;
      scanf("%d%d", &x, &y);
      setv(x - 1, y);
    } else {
      int l, r, k;
      scanf("%d%d%d", &l, &r, &k);
      --l;
      --k;
      long long mm;
      if (k < 0) {
        mm = gmin(l, r);
      } else {
        mm = gmax(l, r);
      }
      printf("%lld\n", gsum(l, r) + mm * k);
    }
  }
}
