Pagini recente » Borderou de evaluare (job #3363881) | Borderou de evaluare (job #1391455) | Cod sursa (job #3364153) | Cod sursa (job #1421998) | Cod sursa (job #3364352)
/// problema datorii infoarena
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int N, M, v[15005], AIB[15005];
void citire()
{
fin>>N>>M;
for(int i = 1; i <= N; i++)
{
fin>>v[i];
}
}
void construireAIB()
{
for(int i = 1; i <= N; i++)
{
AIB[i] += v[i];
int tata = i + (i & (-i));
if(tata <= N)
{
AIB[tata] += AIB[i];
}
}
}
void update(int T, int V)
{
for(int x = T; x <= N; x += (x & (-x)))
{
AIB[x] += V;
}
}
int getSum(int poz)
{
/// calculeaza suma din v de la 1 la poz
int sum = 0;
for(int x = poz; x > 0; x -= (x & (-x)))
{
sum += AIB[x];
}
return sum;
}
void operatii()
{
bool tip;
int x,y;
while(M--)
{
fin>>tip>>x>>y;
if(tip == 0)
{
/// operatie de tip v[x] -= y
update(x, -y);
}
else
{
fout<< getSum(y) - getSum(x - 1)<<'\n';
}
}
}
int main()
{
ios::sync_with_stdio(false);
citire();
construireAIB();
operatii();
return 0;
}