Pagini recente » Cod sursa (job #1749620) | Cod sursa (job #1825575) | Cod sursa (job #1997981) | Cod sursa (job #2055340) | Cod sursa (job #1513273)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int NMax = 15e3 + 5;
int n;
int Aib[NMax];
inline void Update(int pos, const int &sum){
while(pos <= n){
Aib[pos] += sum;
pos += (pos & (-pos));
}
}
inline int Query(int pos){
int sum = 0;
while(pos > 0){
sum += Aib[pos];
pos -= (pos & (-pos));
}
return sum;
}
int main(){
int m, type, a, b;
fin >> n >> m;
for(int i = 1; i <= n; i++){
fin >> a;
Update(i, a);
}
for(int i = 1; i <= m; i++){
fin >> type >> a >> b;
if(type){
fout << Query(b) - Query(a - 1) << "\n";
} else {
Update(a, -b);
}
}
return 0;
}