Pagini recente » Cod sursa (job #1635212) | Cod sursa (job #49081) | Cod sursa (job #1542587) | Cod sursa (job #753505) | Cod sursa (job #1106071)
#include<fstream>
using namespace std;
int N,M,aib[15010];
void update(int val, int nod) {
while(nod<=N) {
aib[nod]+=val;
nod+=(nod&-nod);
}
}
int suma (int nod){
int suma=0;
while(nod>=1) {
suma+=aib[nod];
nod-=(nod&-nod);
}
return suma;
}
int main () {
ifstream in("datorii.in");
ofstream out("datorii.out");
int x,y,i,tip;
in>>N>>M;
for(i=1;i<=N;i++) {
in>>x;
update(x,i);
}
for(i=1;i<=M;i++) {
in>>tip;
if(tip==0) {
in>>x>>y;
update(-y,x);
}
if(tip==1) {
in>>x>>y;
out<<suma(y)-suma(x-1)<<'\n';
}
}
in.close();
out.close();
return 0;
}