Pagini recente » Cod sursa (job #642538) | Cod sursa (job #3184073) | Cod sursa (job #2983297) | Cod sursa (job #642542) | Cod sursa (job #826115)
Cod sursa(job #826115)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int n, m, a[15010];
inline void Update(int x, int y, int semn)
{
while(x<=n)
{
a[x] += semn*y;
x += (x&-x);
}
}
inline int Query(int x)
{
int s = 0;
while(x)
{
s+=a[x];
x-=(x&-x);
}
return s;
}
inline void Solve()
{
ifstream f("datorii.in");
ofstream g("datorii.out");
f>>n>>m;
int i, x, y, cod;
for(i=1; i<=n; i++)
{
f>>x;
Update(i, x, 1);
}
int val2, val1;
while(m--)
{
f>>cod>>x>>y;
if (cod == 0)
{
Update(x, y, -1);
}
else
{
val2 = Query(y);
val1 = Query(x-1);
//cout<<"y: "<<val2<<"\t\tx-1: "<<val1<<"\n";
g<<(val2-val1)<<"\n";
}
}
f.close();
g.close();
}
int main()
{
Solve();
return 0;
}