Ссылка на задачу: https://cses.fi/problemset/task/1648/
мое решение проблемы:
Код: Выделить всё
#include
using namespace std;
typedef long long ll;
const int NMAX = 200005;
int n, q;
ll a[NMAX], tree[NMAX];
ll sum(int k){
ll s = 0;
while(k>0){
s+=tree[k];
k-=k&-k;
}
return s;
}
void add(int k, ll x){
while(k>n>>q;
for(int i = 1; i>a[i];
add(i, a[i]);
}
while(q--){
int type; cin>>type;
if(type==1){
int k;
ll p;
cin>>k>>p;
add(k, p-a[k]);
a[k] = p;
}
else{
int l, r; cin>>l>>r;
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/67743245/dynamic-range-sum-queries[/url]