Pagini recente » Cod sursa (job #929673) | Cod sursa (job #979985) | Cod sursa (job #1370952) | Cod sursa (job #1798415) | Cod sursa (job #2748658)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int nmax = 15e3 + 5;
int n, m, aib[nmax];
void update(int pos, int val){
for(; pos <= n; pos += pos & -pos)
aib[pos] += val;
}
void read(){
fin >> n >> m;
for(int i = 1; i <= n; i++){
int nr;
fin >> nr;
update(i, nr);
}
}
int query(int pos){
int sum = 0;
for(; pos > 0; pos -= pos & -pos)
sum += aib[pos];
return sum;
}
void solve(){
while(m--){
int tip, a, b;
fin >> tip >> a >> b;
if(tip == 0)
update(a, (-1) * b);
else {
int ans = query(b) - query(a - 1);
fout << ans << "\n";
}
}
}
int main()
{
read();
solve();
return 0;
}