#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
class segment_tree {
int n;
vector<int> seg;
public:
segment_tree(int n) : n(n), seg(2 * n, -inf) {}
void set(int i, int x) {
for (seg[i += n] = x, i >>= 1; i > 0; i >>= 1) {
seg[i] = max(seg[2 * i], seg[2 * i + 1]);
}
}
int query(int l, int r) {
int ans = -inf;
for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) ans = max(ans, seg[l++]);
if (r & 1) ans = max(ans, seg[--r]);
}
return ans;
}
};
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
int solve(const vector<int> &a) {
const int n = a.size();
vector<int64_t> pa(n);
pa[0] = a[0];
for (int i = 1; i < n; ++i) {
pa[i] = pa[i - 1] + a[i];
}
min_heap<pair<int64_t, int>> hp;
for (int j = 0; j < n; ++j) {
hp.push({a[j] + pa[j], j});
}
vector<int> dp(n, 1);
segment_tree st(n);
min_heap<int> q;
for (int i = 1; i < n; ++i) {
while (!hp.empty() && hp.top().first < pa[i - 1]) {
q.push(hp.top().second);
hp.pop();
}
while (!q.empty() && q.top() < i) {
st.set(q.top(), dp[q.top()]);
q.pop();
}
if (0 < pa[i - 1] && pa[i - 1] > a[i]) {
dp[i] = 2;
}
int j_max = lower_bound(pa.begin(), pa.end(), pa[i - 1] - a[i]) - pa.begin();
if (0 <= min(i - 1, j_max) - 1) {
dp[i] = max(dp[i], st.query(0, min(i - 1, j_max) - 1) + 2);
}
}
int ans = dp[n - 1];
for (int i = 0; i < n - 1; ++i) {
int64_t max_sum = pa[n - 1] - pa[i];
if (a[i] < max_sum) {
ans = max(ans, dp[i] + 1);
}
}
return ans;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<int> l(n);
for (int &i : l) {
cin >> i;
}
int q;
cin >> q;
while (q--) {
int x, y, a, b;
cin >> x >> y >> a >> b;
l[x - 1] = y;
vector<int> vec;
for (int i = a; i < b; ++i) {
vec.push_back(l[i]);
}
cout << solve(vec) << '\n';
}
}