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;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
int arr[100005];
int prefix[100005];
void solve(){
int n;
cin >> n;
int lft[n+5];
int rgt[n+5];
for(int x=1;x<=n;x++){
cin >> arr[x];
}
int q;
cin >> q;
int temp,l,r;
for(int x=0;x<q;x++){
cin >> temp >> l >> r;
if(temp==1) arr[l]=r;
else{
prefix[l-1]=0;
for(int y=l;y<=r;y++){
prefix[y]=prefix[y-1]+arr[y];
lft[y]=rgt[y]=y;
}
int counter=0;
for(int y=l;y<=r;y++){
while(lft[y]>l||rgt[y]<r){
if(lft[y]>l&&prefix[rgt[y]]-prefix[lft[y]-1]>=arr[lft[y]-1]){
int hold=lft[y]-1;
lft[y]=min(lft[y],lft[hold]);
rgt[y]=max(rgt[y],rgt[hold]);
}
else if(rgt[y]<r&&prefix[rgt[y]]-prefix[lft[y]-1]>=arr[rgt[y]+1]){
int hold=rgt[y]+1;
lft[y]=min(lft[y],lft[hold]);
rgt[y]=max(rgt[y],rgt[hold]);
}
else break;
}
if(lft[y]==l&&rgt[y]==r) counter++;
}
cout << counter << "\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
//freopen("in.txt","r",stdin);
while(t--){
solve();
}
}
# | 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... |