Cod sursa(job #2652722)

Utilizator rohitrjRohit kumar rohitrj Data 25 septembrie 2020 16:26:39
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto maxn = 100006;
void IOfile(){
freopen("datorii.in", "r", stdin);
freopen("datorii.out", "w", stdout);
}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int fen[maxn];
int n,m;
void add(int ind, int val){
	while(ind <= n){
		fen[ind] += val;
		ind += (ind & (-ind));
	}
}

int get(int ind){
	int res = 0 ;
	while(ind > 0){
		res += fen[ind];
		ind -= (ind & (-ind));
	}
	return res;
}

int32_t main(){
	fastio();
	IOfile();
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		add(i,x);
	}
	while(m--){
		int t;
		cin >> t;
		if(t == 0){
			int  ind , v;
			cin >> ind >> v;
			add(ind,-v);
		}else{
			int l,r;
			cin >> l >>r;
			cout << (get(r) - get(l - 1)) << "\n";
		}
	}
}