Pagini recente » Cod sursa (job #559875) | Cod sursa (job #1402328) | Cod sursa (job #1653029) | Cod sursa (job #1622397) | Cod sursa (job #1651182)
#include <fstream>
#define zeros(x) (x & (-x))
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int AIB[15100],X[15100],N,M,a,b;
bool u;
void add(int x,int pos){
for(pos; pos<=N;pos+=zeros(pos) ){
AIB[pos]+=x;
}
}
void achitare(int x,int pos){
for(pos; pos<=N;pos+=zeros(pos) ){
AIB[pos]-=x;
}
}
int query(int a){
int sum = 0;
for(;a > 0;a -= zeros(a)){
sum+=AIB[a];
}
return sum;
}
int main(){
fin >> N >> M;
for(int i = 1,x;i<=N;i++){
fin >> x;
add(x,i);
}
for(int i = 0;i<M;i++){
fin >> u >> a >> b;
if(u) fout << query(b) - query(a-1) << '\n'; else achitare(b,a);
}
return 0;
}