Cod sursa(job #1850034)

Utilizator sandupetrascoPetrasco Sandu sandupetrasco Data 18 ianuarie 2017 08:55:33
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);
#define tie cin.tie(0);
#define mp make_pair
#define ll long long
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define y second
#define zeros(x) ( (x ^ (x - 1)) & x )

using namespace std;

int AIB[15100], n, m, a, b;
bool u;

void add(int x, int val, bool u)
{
	for (; x <= n; x += zeros(x))
		AIB[x] += (u ? val : -val);
}

int get(int x)
{
	int rs = 0;
	for (; x > 0; x -= zeros(x))
		rs += AIB[x];
	return rs;
}

int main(){
	IOS tie
	ifstream cin("datorii.in");
	ofstream cout("datorii.out");
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a, add(i, a, 1);
	for (int i = 1; i <= m; i++)
	{
		cin >> u >> a >> b;
		if (u) cout << get(b) - get(a-1)  << "\n";
		else add(a, b, 0);
	}
	cerr << "Fucking time elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}