#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;
cin>>n>>q;
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 |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |