#include <iostream>
using namespace std;
/* построение дерева */
void build (int tree[], int arr[], int v, int left, int right) {
if (left == right) {
tree[v] = arr[left];
}
else {
int middle = (left + right) / 2;
build (tree, arr, v*2, left, middle);
build (tree, arr, v*2+1, middle+1, right);
tree[v] = tree[v*2] + tree[v*2+1];
}
}
/* запрос суммы */
int sum (int tree[], int v, int left, int right, int from, int to) {
if (from > to) {
return 0;
}
if (from == left && to == right) {
return tree[v];
}
int middle = (left + right) / 2;
return sum (tree, v*2, left, middle, from, min(to,middle))
+ sum (tree, v*2+1, middle+1, right, max(from,middle+1), to);
}
/* операция присваивания*/
void update (int tree[], int v, int left, int right, int index, int new_val) {
if (left == right) {
tree[v] = new_val;
}
else {
int middle = (left + right) / 2;
if (index <= middle) {
update (tree, v*2, left, middle, index, new_val);
}
else {
update (tree, v*2+1, middle+1, right, index, new_val);
}
tree[v] = tree[v*2] + tree[v*2+1];
}
}
int main() {
int n, q, i, d, from, to;
char query;
cin >> n >> q;
int size = 2*n; /* максимальный размер дерева*/
int arr[n+1], tree[size];
for(int i = 0; i < n; i++){
cin >> arr[i];
}
build(tree, arr, 1, 0, n-1); /* передаем функции построения массив для записи
дерева, исходный массив, корень и границы отрезка,
принадлежащего корню*/
for (q; q>0; q--) {
cin >> query;
if(query == '=') {
cin >> i >> d;
update(tree, 1, 0, n-1, i-1, d);
}
else if (query == '?') {
cin >> from >> to;
cout << sum(tree, 1, 0, n-1, from-1, to-1) << endl;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLyog0L/QvtGB0YLRgNC+0LXQvdC40LUg0LTQtdGA0LXQstCwICovCnZvaWQgYnVpbGQgKGludCB0cmVlW10sIGludCBhcnJbXSwgaW50IHYsIGludCBsZWZ0LCBpbnQgcmlnaHQpIHsgICAKCWlmIChsZWZ0ID09IHJpZ2h0KSB7CgkJdHJlZVt2XSA9IGFycltsZWZ0XTsKCX0KCWVsc2UgewoJCWludCBt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