Pagini recente » Cod sursa (job #2482558) | Cod sursa (job #2418347) | Cod sursa (job #2127204) | Cod sursa (job #935010) | Cod sursa (job #990874)
Cod sursa(job #990874)
#include <fstream>
short aib[15001];
int main(){
std::ifstream fin("datorii.in");
std::ofstream fout("datorii.out");
unsigned N,M;
fin>>N>>M;
unsigned temp1; int temp2; char c;
for(unsigned i=1;i<=N;++i){
fin>>temp2;
temp1=i;
while(temp1<=N){
aib[temp1]+=temp2;
temp1 += temp1&(-temp1);
}
}
while(M--){
fin>>c>>temp1>>temp2;
if(c=='0'){
while(temp1<=N){
aib[temp1]-=temp2;
temp1 += temp1&(-temp1);
}
}
else{
unsigned sum1=0,sum2=0;
temp1--;
while(temp1>0){
sum1+=aib[temp1];
temp1&=temp1-1;
}
while(temp2>0){
sum2+=aib[temp2];
temp2&=temp2-1;
}
fout<<sum2-sum1<<'\n';
}
}
}