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;
ll n,v[100005],q,s[100005],mars[100005];
int solve(int l,int r)
{
s[l-1]=0;
mars[l-1]=0;
for(int i=l;i<=r;i++)
{
s[i]=s[i-1]+v[i];
mars[i]=0;
}
stack<int> coada;
for(int i=l;i<=r;i++)
{
while(!coada.empty()&&v[coada.top()]<v[i])
coada.pop();
int st=l-1;
if(!coada.empty())
st=coada.top();
if(s[i-1]-s[st]<v[i])
{
mars[st+1]++;
mars[i]--;
}
coada.push(i);
}
while(!coada.empty())
coada.pop();
for(int i=r;i>=l;i--)
{
while(!coada.empty()&&v[coada.top()]<v[i])
coada.pop();
int dr=r+1;
if(!coada.empty())
dr=coada.top();
if(s[dr-1]-s[i]<v[i])
{
mars[i+1]++;
mars[dr]--;
}
coada.push(i);
}
int ans=0;
for(int i=l;i<=r;i++)
{
mars[i]+=mars[i-1];
if(mars[i]==0)
ans++;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>v[i];
cin>>q;
if(q<=1000)
{
while(q--)
{
int tip;
cin>>tip;
if(tip==1)
{
int poz,val;
cin>>poz>>val;
v[poz]=val;
}
else
{
int l,r;
cin>>l>>r;
cout<<solve(l,r)<<'\n';
}
}
return 0;
}
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... |