Cod sursa(job #2817942)

Utilizator LionMan101Achim-Panescu Silvian LionMan101 Data 14 decembrie 2021 19:57:46
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 3.02 kb
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int INF=1e9+7;
const ll INFF=1e18+7;
#define nl '\n'
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { cout << x; }
void __print(unsigned x) { cout << x; }
void __print(unsigned long x) { cout << x; }
void __print(unsigned long long x) { cout << x; }
void __print(float x) { cout << x; }
void __print(double x) { cout << x; }
void __print(long double x) { cout << x; }
void __print(char x) { cout << '\'' << x << '\''; }
void __print(const char* x) { cout << '\"' << x << '\"'; }
void __print(const string& x) { cout << '\"' << x << '\"'; }
void __print(bool x) { cout << (x ? "true" : "false"); }
template<typename T, typename V>
void __print(const pair<T, V>& x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; }
template<typename T>
void __print(const T& x) { int f = 0; cout << '{'; for (auto& i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; }
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); }
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

vector<int> a(15001), segTree(60005);

void build(int v, int left, int right){
    if(left==right){
        segTree[v]=a[left];
        return;
    }
    int mid=(left+right)/2;
    build(2*v, left, mid);
    build(2*v+1, mid+1, right);
    segTree[v]=segTree[2*v]+segTree[2*v+1];
}

void update(int v, int cleft, int cright, int index, int val){
    if(cleft==cright){
        segTree[v]+=val;
    }
    else{
        int mid=(cleft+cright)/2;
        if(index<=mid) update(2*v,cleft,mid,index,val);
        else update(2*v+1,mid+1,cright,index,val);
        segTree[v]=segTree[2*v]+segTree[2*v+1];
    }
}

int query(int v, int cleft, int cright, int left, int right){
    if(left<=cleft && right>=cright){
        return segTree[v];
    }
    else{
        int mid=(cleft+cright)/2;
        if(right<=mid) return query(2*v, cleft, mid, left, right);
        if(left>mid) return query(2*v+1, mid+1, cright, left, right);
        return query(2*v, cleft, mid, left, right) + query(2*v+1, mid+1, cright, left, right);
    }
}

void solve()
{
    int n,q;
    cin>>n>>q;
    // debug(n,q);
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    build(1,1,n);
    for(int i=0; i<q; i++){
        int c,x,y;
        cin>>c>>x>>y;
        if(c){
            cout<<query(1,1,n,x,y)<<nl;
        }
        else{
            update(1,1,n,x,-y);
        }
    }
    // debug("OK");
}

int main()
{
// #ifndef ONLINE_JUDGE
    freopen("datorii.in", "r", stdin);
    freopen("datorii.out", "w", stdout);
// #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    // int t;
    // cin >> t;
    for(int tt=1; tt<=t; tt++){
        // cout<<"#Case "<<t<<nl;
        solve();
    }
    return 0;
}