/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 200;
int n;
ll a[N], pref[N];
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
a[0] = -1;
int q; cin >> q;
for(int i = 0; i < q; ++i){
int x, y, A, B; cin >> x >> y >> A >> B;
++A;
a[x] = y;
pref[0] = 0;
for(int j = 1; j <= n; ++j){
pref[j] = pref[j - 1] + a[j];
}
vector<array<ll, 2>> dp(n + 2);
dp[A][0] = 1;
dp[A][1] = 1;
for(int j = A + 1; j <= B; ++j){
int l = A, r = j - 1, go = j;
while(l <= r){
int m = l + r>>1;
if(pref[j - 1] - pref[m - 1] > a[j]){
go = m;
l = m + 1;
}else r = m - 1;
}
if(go == j) dp[j][0] = 1;
else dp[j][0] = dp[go][1] + 1;
for(int k = 0; k < MX; ++k){
if(j - k < A) continue;
if(pref[j] - pref[j - k - 1] > a[j - k - 1] || j - k == A){
// cout << a[j-k-1] << ' ' << pref[j] - pref[j - k - 1] << "f\n";
dp[j][1] = max(dp[j][1], dp[j - k - 1][0] + 1);
}
}
}
cout << max(dp[B][0], dp[B][1]) << '\n';
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |