This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
ll n, q;
vector<ll> a, ans;
void f(ll l, ll r){
if(l==r){
ans[l]=1;
return;
}
ll mx=0, mxp=0;
for(ll i=l; i<=r; i++){
if(mx<a[i]) mx=a[i], mxp=i;
}
ans[mxp]=1;
ll cnt=0;
for(ll i=l; i<mxp; i++) cnt+=a[i];
if(cnt>=mx) f(l, mxp-1);
cnt=0;
for(ll i=mxp+1; i<=r; i++) cnt+=a[i];
if(cnt>=mx) f(mxp+1, r);
}
int main() {
cin >> n;
a.assign(n, -1);
for(ll i=0; i<n; i++) cin >> a[i];
ans.assign(n, 0);
cin >> q;
while(q--){
ll t, x, y; cin >> t >> x >> y;
if(t==1) a[x-1]=y;
else{
ans.assign(n, 0);
f(x-1, y-1);
ll cnt=0;
for(auto& u : ans) cnt+=u;
cout << cnt << endl;
}
}
}
# | 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... |