Pagini recente » Cod sursa (job #2049455) | Cod sursa (job #2654048) | Cod sursa (job #1090763) | Cod sursa (job #1951896) | Cod sursa (job #935251)
Cod sursa(job #935251)
/// Craciun Catalin (c)
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int A[15005],n,m;
void achitare(int x, int val);
int suma(int x);
int main(){
int q,x,y;
int i;
f>>n>>m;
for(i=1;i<=n;i++){
f>>x;
achitare(i,x);
}
while (m--){
f>>q>>x>>y;
if (q==0)
achitare(x,-y);
else
g<<suma(y)-suma(x-1)<<"\n";
}
f.close();
g.close();
return 0;
}
int suma(int x){
int suma(0);
while (x){
suma+=A[x];
x-=x&-x;
}
return suma;
}
void achitare(int x, int val){
while (x<=n){
A[x]+=val;
x+=x&-x;
}
}