Pagini recente » Cod sursa (job #282620) | Cod sursa (job #1443053) | Istoria paginii runda/captainbobulous/clasament | Cod sursa (job #1892076) | Cod sursa (job #1654048)
#include <bits/stdc++.h>
#define NMAX 15005
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n,m;
vector<int> tree(NMAX);
void update(int poz, int val)
{
while(poz <= n)
tree[poz] -= val, poz += poz & -poz;
}
void update2(int poz, int val)
{
while(poz <= n)
tree[poz] += val, poz += poz & -poz;
}
int query(int poz)
{
int S = 0;
while(poz)
S += tree[poz] > 0 ? tree[poz] : 0 , poz -= poz & -poz;
return S;
}
int main()
{
fin >> n >> m;
int val,a,b,op;
for(int i = 1 ; i <= n ; ++ i)
fin >> val, update2(i,val);
while(m --)
{
fin >> op >> a >> b;
switch(op)
{
case 0: update(a,b); break;
case 1: fout << query(b) - query(a-1) << "\n"; break;
}
}
return 0;
}