Pagini recente » Cod sursa (job #1716794) | Cod sursa (job #497654) | Cod sursa (job #2356376) | Cod sursa (job #1442129) | Cod sursa (job #1448538)
#include<fstream>
using namespace std;
ifstream f("datorii.in"); ofstream g("datorii.out");
int AIB[15010],m,n;
inline int zero(int x) {return (-x)&x;}
void update(int poz, int val)
{ while(poz <= n) {AIB[poz]+=val; poz+=zero(poz);}}
int calc(int poz)
{ int s=0;
while(poz) {s+=AIB[poz]; poz-=zero(poz);}
return s;
}
int main()
{ int i,tip,x,y;
f>>n>>m;
for(i=1;i<=n;++i) {f>>x; update(i,x);}
while(m--)
{ f>>tip>>x>>y;
if(tip) g<<calc(y)-calc(x-1)<<"\n"; else update(x,-y);
}
return 0;
}