Pagini recente » Borderou de evaluare (job #1525885) | Cod sursa (job #665089) | Cod sursa (job #349514) | Cod sursa (job #2747559) | Cod sursa (job #942825)
Cod sursa(job #942825)
#include<fstream>
using namespace std;
int n, aib[15001];
inline int lsb(int &x){
return x & -x;
}
void update(int val, int pos){
while(pos <= n){
aib[pos] += val;
pos += lsb(pos);
}
}
int query(int pos){
int ans = 0;
while(pos > 0){
ans += aib[pos];
pos -= lsb(pos);
}
return ans;
}
int main(){
ifstream in("datorii.in");
ofstream out("datorii.out");
int m;
in >> n >> m;
for(int i = 1; i <= n; ++i){
int x;
in >> x;
update(x, i);
}
for(int i = 1; i <= m; ++i){
int tip, x, y;
in >> tip >> x >> y;
if(tip == 0)
update(-y, x);
else
out << query(y) - query(x - 1) << "\n";
}
return 0;
}