Pagini recente » Cod sursa (job #633766) | Diferente pentru utilizator/mihnea.anghel intre reviziile 43 si 31 | Diferente pentru utilizator/mihnea.anghel intre reviziile 43 si 33 | Cod sursa (job #2109940) | Cod sursa (job #772806)
Cod sursa(job #772806)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int AIB[15010], M, N;
inline int lsb(int x)
{
return ( x & (-x) );
}
void update(int poz, int val)
{
while(poz <= N){
AIB[poz] += val;
poz += lsb(poz);
}
}
int query(int poz)
{
int s = 0;
while(poz){
s += AIB[poz];
poz -= lsb(poz);
}
return s;
}
int main()
{
int i, tip, x, y;
in >> N >> M;
for(i = 1; i <= N; ++i){
in >> x;
update(i, x);
}
while(M--){
in >> tip >> x >> y;
if(tip)
out << query(y) - query(x - 1) << "\n";
else
update(x, -y);
}
return 0;
}