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 ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,q;
int arr[100005];
vector<int> al[100005];
ii dfs(int i){
int tot=arr[i];
int num=1;
for (auto it:al[i]){
auto temp=dfs(it);
if (temp.fi>=arr[i]) num+=temp.se;
tot+=temp.fi;
}
return {tot,num};
}
int solve(int i,int j){
rep(x,i,j+1) al[x].clear();
vector<int> stk;
rep(x,i,j+1){
while (!stk.empty() && arr[stk.back()]<=arr[x]){
int temp=stk.back(); stk.pob();
if (stk.empty() || arr[stk.back()]>arr[x]) al[x].pub(temp);
else al[stk.back()].pub(temp);
}
stk.pub(x);
}
while (sz(stk)>=2){
int temp=stk.back(); stk.pob();
al[stk.back()].pub(temp);
}
return dfs(stk.back()).se;
}
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n;
rep(x,1,n+1) cin>>arr[x];
cin>>q;
int a,b;
rep(x,0,q){
cin>>a;
if (a==1){
cin>>a>>b;
arr[a]=b;
}
else{
cin>>a>>b;
cout<<solve(a,b)<<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... |