Cod sursa(job #1979187)

Utilizator brczBereczki Norbert Cristian brcz Data 9 mai 2017 21:38:57
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

// #define int long long

const int maxn = 100003;
const int maxk = 15003;



int aib[maxk];

int n,m;

int next(int x){
	return x&-x;
}

void update(int x,int adder){

	for(int i=x;i<=n;i+=next(i)){
		aib[i]+=adder;
	}
}

int query(int x){
	int ret = 0;
	for(int i=x;i>=1;i-=next(i)){
		ret+=aib[i];
	}
	return ret;
}

int32_t main(){

	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif

	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	int x,y,op;
	for(int i=1;i<=n;i++){
		cin >> x;
		update(i,x);
	}
	for(int i=0;i<m;i++){
		cin >> op >> x >> y;
		if(!op){
			update(x,-y);
		}
		else{
			cout << query(y) - query(x-1) << '\n';
		}
	}


	return 0;
}