Pagini recente » Cod sursa (job #182795) | Cod sursa (job #1766119) | Cod sursa (job #3266679) | Cod sursa (job #2469264) | Cod sursa (job #2750635)
#include <fstream>
using namespace std;
int aib[100005];
int query(int pos)
{
int s = 0;
while(pos>0)
{
s = s + aib[pos];
pos = pos & (pos - 1);
}
return s;
}
void update(int pos,int val,int n)
{
while(pos <= n)
{
aib[pos] = aib[pos] + val;
pos = pos + (pos ^ (pos & (pos - 1)));
}
}
int main()
{
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++)
{
int x;
cin >> x;
update(i, x, n);
}
for(int i = 0; i < m; i ++)
{
int x, y, cer;
cin >> cer;
cin >> x >> y;
if(!cer)
{
y*= -1;
update(x, y, n);
}
else
{
cout << query(y) - query(x - 1) << '\n';
}
}
return 0;
}