Cod sursa(job #1405028)

Utilizator andreey_047Andrei Maxim andreey_047 Data 28 martie 2015 19:30:16
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <cstdio>
#define zeros(x) ((x^(x-1))&x)
#define nmax 15005
using namespace std;
int n,AIB[nmax];
inline void Adun(int poz,int q){
 for(int i = poz ; i <= n; i+=zeros(i))
    AIB[i]+=q;
}
inline void Scad(int poz,int q){
 for(int i = poz ; i <= n; i+=zeros(i))
    AIB[i]-=q;
}
inline int Compute(int x){
    int sum=0;
 for(int i = x; i > 0; i-=zeros(i))
    sum+=AIB[i];
 return sum;
}
int main(){
    int q,x,i,key,y;
    freopen("datorii.in","r",stdin);
    freopen("datorii.out","w",stdout);
    scanf("%d%d\n",&n,&q);
    for(i=1;i<=n;i++)
        scanf("%d ",&x),Adun(i,x);
    while(q--){
        scanf("%d %d %d\n",&key,&x,&y);
        if(key){
            printf("%d\n",Compute(y)-Compute(x-1));
            continue;
        }
        Scad(x,y);
    }
    return 0;
}