Cod sursa(job #3354375)

Utilizator 20r50Gheorghies Robert 20r50 Data 17 mai 2026 18:34:38
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.14 kb
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#define ll long long
#define ll int
#define ld long double
#define i27 __int128
using namespace std;
const ll NMAX=15e3+5,NMAX2=1e9+4;
const ll TIME_MAX=9e8+5;
const ll MOD=72;
const unsigned ll MOD2=1e19;
ll get_time(){
    return chrono::steady_clock::now().time_since_epoch().count();
}
/*int v[NMAX];
bitset<NMAX> c;
//mii fr;
void ciur(){
    c[0]=c[1]=1;
    for(ll i=2;i<NMAX;i++){
        if(c[i]==0){
            //v.push_back(i);
            for(ll j=i;j<NMAX;j+=i){
                c[j]=1;
                v[j]++;
            }
        }
    }
}*/
/*ll N(ll n){
    ll d=1;
    for(ll i=0;v[i]*v[i]<=n;i++){
        ll p=0;
        while(n%v[i]==0){
            n/=v[i];
            p++;
        }
        d*=p+1;
    }
    if(n>1)
        d*=2;
    return d;
}*/
int bit[NMAX],v[NMAX];
void probleme()
{
    //ciur();
    //test();
    ll n,q;
    cin>>n>>q;
    for(ll i=0;i<n;i++){
        cin>>v[i];
        for(ll j=i+1;j<NMAX;j+=j&(-j))
            bit[j]+=v[i];
    }
    for(ll i=0;i<q;i++){
        ll cer,a,b;
        cin>>cer>>a>>b;
        cer++;
        if(cer==1){
            for(ll j=a;j<NMAX;j+=j&(-j))
                bit[j]-=b;
        }
        if(cer==2){
            ll s1=0,s2=0;
            a--;
            while(a){
                s1+=bit[a];
                a-=a&(-a);
            }
            while(b){
                s2+=bit[b];
                b-=b&(-b);
            }
            cout<<s2-s1<<'\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("thing2.in","r",stdin);
    freopen("thing2.out","w",stdout);
#else
    freopen("datorii.in","r",stdin);
    freopen("datorii.out","w",stdout);
#endif
    ll start=get_time();
    //ll t; cin>>t; while(t--)
    probleme();
    ll x=get_time()-start;
    cerr<<"------>secunde - "<<x/1000000000<<'\n';
    cerr<<"-->milisecunde - "<<x/1000000%1000<<'\n';
    cerr<<"->microsecunde - "<<x/1000%1000<<'\n';
    cerr<<"-->nanosecunde - "<<x%1000;
    return 0;
}