Pagini recente » Cod sursa (job #169530) | Cod sursa (job #2436076) | Cod sursa (job #1470940) | Cod sursa (job #2348957) | Cod sursa (job #871753)
Cod sursa(job #871753)
#include<cstdio>
#include<fstream>
#define NMax 1005
using namespace std;
int n,a[NMax];
void update (int poz, int val)
{while (poz<=n){
a[poz]+=val;
poz+=(poz & (-poz)); }}
int inter(int poz)
{ int sum=0;
while (poz>=1)
{ sum+=a[poz];
poz-=(poz & (-poz));}
return sum;}
int main ()
{
int m,i,tip,x,y;
ifstream f("datorii.in");
ofstream g("datorii.out");
f>>n>>m;
for (i=1;i<=n;i++)
{ f>>x;
update(i,x); }
for (i=1;i<=m;i++)
{ f>>tip>>x>>y;
if (!tip)
update(x,-y);
else
g<<(inter(y)-inter(x-1))<<"\n";}
return 0; }