Pagini recente » Cod sursa (job #1928363) | Cod sursa (job #1681686) | Cod sursa (job #2326886) | Cod sursa (job #2436509) | Cod sursa (job #3217458)
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define chad char
#define mod 1'000'000'007
#define dim 100005
#define lim 1000000
#define INF 1000000000
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n,q;
int a[15002];
struct fenw
{
vector<ll> aib;
int n;
fenw(int _n)
{
this->n=_n;
this->aib=vector<ll>(_n+5,0);
}
void update(int pos, ll val)
{
for(int i=pos; i<=n; i+=(i&-i))
aib[i]+=val;
}
ll query(int pos)
{
ll ans=0;
for(int i=pos; i; i-=(i&-i))
ans+=aib[i];
return ans;
}
};
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n >> q;
for(int i=1; i<=n; i++)
fin >> a[i];
fenw v(n);
for(int i=1; i<=n; i++)
v.update(i,a[i]);
while(q--)
{
int tip,x,y;
fin >> tip >> x >> y;
if(!tip)
{
v.update(x,-y);
}
else
{
fout << v.query(y)-v.query(x-1) << "\n";
}
}
return 0;
}