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
const int MAXN=1e5+7;
int mod;
struct node{
int maior,soma;
node operator+(node aux){
return{max(maior,aux.maior),soma+aux.soma};
}
};
node seg[4*MAXN];
int arr[MAXN];
void build(int pos, int ini, int fim){
if(ini==fim){
seg[pos]={arr[ini],arr[ini]};
return;
}
int m=(ini+fim)/2;
int e=2*pos,d=2*pos+1;
build(e,ini,m);
build(d,m+1,fim);
seg[pos]=seg[e]+seg[d];
}
int somar(int pos, int ini,int fim, int p, int q){
if(ini>q||fim<p)return 0;
if(p<=ini&&fim<=q)return seg[pos].soma;
int m=(ini+fim)/2;
int e=2*pos,d=2*pos+1;
return somar(e,ini,m,p,q)+somar(d,m+1,fim,p,q);
}
void mudar(int pos, int ini, int fim, int ind,int val){
if(ini>ind||fim<ind)return;
if(ini==fim){
seg[pos]={val,val};
return;
}
int m=(ini+fim)/2;
int e=2*pos,d=2*pos+1;
mudar(e,ini,m,ind,val);
mudar(d,m+1,fim,ind,val);
seg[pos]=seg[e]+seg[d];
}
int32_t main(){
int n,q,k;
cin>>n>>q>>k;
for(int i=1;i<=n;i++)cin>>arr[i];
build(1,1,n);
while(q--){
int tipo,a,b;
cin>>tipo>>a>>b;
if(tipo==1){
cout<<somar(1,1,n,a,b)<<"\n";
}
else if(tipo==2){
}
else{
mudar(1,1,n,a,b);
}
}
}
# | 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... |