Pagini recente » Cod sursa (job #2494162) | Cod sursa (job #539163) | Cod sursa (job #2665250) | Cod sursa (job #293538) | Cod sursa (job #2835106)
///#include <iostream>
#include <fstream>
using namespace std;
const int SIZE = 1e5+10;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int n, m, aux;
int cer, a, b;
int v[SIZE];
int getLastBit(int n)
{
return (n & (n ^ (n-1)));
}
void update(int pos, int val)
{
while(pos<=n)
{
v[pos] += val;
pos += getLastBit(pos);
}
}
int query(int pos)
{
int rez = 0, p2;
while(pos)
{
p2 = getLastBit(pos);
rez += v[pos];
pos -= p2;
}
return rez;
}
int main()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>aux, update(i, aux);
while(m--)
{
cin>>cer>>a>>b;
if(cer) cout<<query(b) - query(a-1)<<'\n';
else update(a, -b);
}
return 0;
}