Pagini recente » Cod sursa (job #3170610) | Cod sursa (job #2770374) | Cod sursa (job #2525613) | Cod sursa (job #897167) | Cod sursa (job #2756274)
#include <iostream>
#include <fstream>
#define NMAX 15000
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
int N, M;
int aib[NMAX + 1];
void adaugAIB(int poz, int val){
for(int i = poz; i <= N; i = i + ( (i ^ (i - 1)) + 1 ) / 2 ){
aib[i] += val;
}
}
int sumaAIB(int poz){
int rez = 0;
for(int i = poz; i > 0; i = i - ( (i ^ (i - 1)) + 1 ) / 2 ){
rez = rez + aib[i];
}
return rez;
}
int main()
{
fin >> N >> M;
for(int i = 1; i <= N; i++){
int x;
fin >> x;
adaugAIB(i, x);
}
for(int q = 1; q <= M; q++){
int tip, a, b;
fin >> tip >> a >> b;
if(tip == 0){
adaugAIB(a, -b);
}
else {
fout << sumaAIB(b) - sumaAIB(a - 1) << "\n";
}
}
return 0;
}