Cod sursa(job #3245386)

Utilizator MihneaStoicaMihnea Teodor Stoica MihneaStoica Data 28 septembrie 2024 19:10:27
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.84 kb
// "I am the true mogger."
// 					-MihneaTheMogger
// 
// prob Datorii
// 
// tl 75
// ml 64
// 
// LOT

#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false);\
                               cin.tie(nullptr);\
                 			  cout.tie(nullptr);
using namespace std;

#define int int64_t 
#define YES cout<<"YES"    
#define YESn cout<<"YES\n" 
#define NO cout<<"NO"     
#define NOn cout<<"NO\n"       

#define MORE_TESTS 0   
#define FASTIO 1     
int32_t TESTCASE_COUNT = 1, TESTCASE;

const int nlim = 15001;
int aint[nlim * 4];

void update (int nod, int st, int dr, int pos, int val)
{
	if (st == dr) {
		aint[nod] += val;
		return;
	}
	else {
		int mid = (st + dr) / 2;
		if (st <= pos && pos <= mid) {
			update (nod * 2 + 1, st, mid, pos, val);
		}
		else {
			update (nod * 2 + 2, mid + 1, dr, pos, val);
		}
		aint[nod] = aint[nod * 2 + 1] + aint[nod * 2 + 2];
	}
}

int query (int nod, int st, int dr, int l, int r)
{
	if (st > r || dr < l) {
		return 0;
	}
	if (l <= st && dr <= r) {
		return aint[nod];
	}
	else {
		int mid = (st + dr) / 2;
		return query(nod * 2 + 1, st, mid, l, r) + query(nod * 2 + 2, mid + 1, dr, l, r);
	}
}

void Solve ()
{
#ifndef LOCAL
	freopen("datorii.in", "r", stdin);
	freopen("datorii.out", "w", stdout);
#endif
	
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		int x; cin >> x;
		update(1, 1, n, i, x);
	}
	
	while (m --) {
		int op; cin >> op;
		if (op == 0) {
			int pos, val; cin >> pos >> val;
			update(1, 1, n, pos, -val);
		}
		else {
			int l, r; cin >> l >> r;
			cout << query (1, 1, n, l, r) << '\n';
		}
	}
}

/*

*/

int32_t main ()
{
    #if FASTIO == 1
    FastIO;
    #endif
    #if MORE_TESTS == 1
    cin >> TESTCASE_COUNT;
    #endif
    for (TESTCASE = 1; TESTCASE <= TESTCASE_COUNT; TESTCASE ++)
        Solve ();
}

/*
___  ___          _        ______         ___  ____ _                    _____ _         ___  ___
|  \/  |         | |       | ___ \        |  \/  (_) |                  |_   _| |        |  \/  |
| .  . | __ _  __| | ___   | |_/ /_   _   | .  . |_| |__  _ __   ___  __ _| | | |__   ___| .  . | ___   __ _  __ _  ___ _ __
| |\/| |/ _` |/ _` |/ _ \  | ___ \ | | |  | |\/| | | '_ \| '_ \ / _ \/ _` | | | '_ \ / _ \ |\/| |/ _ \ / _` |/ _` |/ _ \ '__|
| |  | | (_| | (_| |  __/  | |_/ / |_| |  | |  | | | | | | | | |  __/ (_| | | | | | |  __/ |  | | (_) | (_| | (_| |  __/ |
\_|  |_/\__,_|\__,_|\___|  \____/ \__, |  \_|  |_/_|_| |_|_| |_|\___|\__,_\_/ |_| |_|\___\_|  |_/\___/ \__, |\__, |\___|_|
                                   __/ |                                                                __/ | __/ |
                                  |___/                                                                |___/ |___/
*/