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>
#define ll long long
using namespace std;
ll N,Q,niz[250005];
/*
1 veci
-1 manji
*/
ll duzina(ll gde,ll duz,ll vp,ll tip,ll kraj){
if(gde>kraj)
return 0;
duz+=niz[gde];
// cout<<gde<<" "<<duz<<" "<<vp<<" "<<tip<<" "<<kraj<<endl;
if(duz*tip>vp*tip)
return 1+duzina(gde+1,0,duz,tip*-1,kraj);
if(tip==1)
return duzina(gde+1,duz,vp,tip,kraj);
else
return duzina(gde+1,0,vp+niz[gde],tip,kraj);
}
int main(){
cin>>N;
for(int i=1;i<=N;i++)
cin>>niz[i];
cin>>Q;
while(Q--){
ll a,b,L,R;
cin>>a>>b>>L>>R;
L++;
niz[a]=b;
cout<<max(duzina(L,0,1e18,-1,R),duzina(L,0,-1e18,1,R))<<endl;
}
return 0;
}
/*
4
6 2 3 2
1
3 2 1 3
*/
# | 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... |