Pagini recente » Cod sursa (job #202226) | Clasament tralala3 | Cod sursa (job #2148968) | Cod sursa (job #307680) | Cod sursa (job #2423897)
#include <iostream>
#include <fstream>
#define lsb(x) ((x^(x-1))&x)
#define Nmax 15005
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
int n, m;
int aib[Nmax];
void update(int poz, int val, int semn)
{
val*=semn;
for (; poz <= n; poz+=lsb(poz)) aib[poz]+=val;
}
void read()
{
f >> n >> m;
for (int i = 1, x; i <= n; i++)
{
f >> x;
update(i, x, 1);
}
}
int query(int poz)
{
int s=0;
for (; poz > 0; poz-=lsb(poz)) s+=aib[poz];
return s;
}
void solve()
{
int c, x, y;
while (m--)
{
f >> c >> x >> y;
if (c == 0)
{
update(x, y, -1);
}
else
{
g << query(y)-query(x-1) << '\n';
}
}
}
int main()
{
read();
solve();
return 0;
}