Pagini recente » Cod sursa (job #640332) | Cod sursa (job #718473) | Cod sursa (job #410704) | Cod sursa (job #300215) | Cod sursa (job #2393461)
#include <bits/stdc++.h>
#pragma region TEMPLATE
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
#define dbg(x) cerr<<#x": "<<(x)<<'\n'
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<'\n'
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long =0;_<n;++)cerr<<(x)[_]<<' ';cerr<<'\n';}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define pb push_back
#define INF 2000000010
#define MOD 1000000007
#define MOD2 998244353
#define ST_SIZE 1048600
#define QMAX
#define PI 3.14159265359
#define zeros(x) x^(x-1)&x // x&(-x)
#define NMAX 100010
#define MMAX NMAX * NMAX
using namespace std;
ofstream fout("datorii.out");
ifstream fin("datorii.in");
template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
out << '(' << item.first << ", " << item.second << ')';
return out;
}
template<typename T>
ostream& operator <<(ostream &out, const vector<T> &v) {
for(const auto &item : v) out << item << ' ';
return out;
}
#pragma endregion
int aib[15010], n;
void updateAdd(int pos, int val){
for(int i = pos; i <= n; i += zeros(i)){
aib[i] += val;
}
}
void updateSub(int pos, int val){
for(int i = pos; i <= n; i += zeros(i)){
aib[i] -= val;
}
}
int sum(int pos){
int sum = 0;
for(int i = pos; i >= 1; i -= zeros(i)){
sum += aib[i];
}
return sum;
}
int sum(int x, int y){
if(x > y) return 0;
return sum(y) - sum(x - 1);
}
int main(){
int m;
fin >> n >> m;
for(int i = 1; i <= n; i++){
int x;
fin >> x;
updateAdd(i, x);
}
for(int i = 1; i <= m; i++){
int o, x, y;
fin >> o >> x >> y;
switch(o){
case 0: updateSub(x, y); break;
case 1: fout << sum(x, y) << '\n'; break;
}
}
return 0;
}