Mai intai trebuie sa te autentifici.
Cod sursa(job #2893015)
| Utilizator | Data | 24 aprilie 2022 16:01:38 | |
|---|---|---|---|
| Problema | Datorii | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.74 kb |
#include<fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int aib[15002], n, m;
void update(int poz,int val)
{
while(poz <= n)
{
aib[poz] += val;
poz += (poz&(-poz));
}
}
int ras(int poz)
{
int ans = 0;
while(poz > 0)
{
ans += aib[poz];
poz -= (poz&(-poz));
}
return ans;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i++)
{
int x;
fin >> x;
update(i, x);
}
for(int i = 1; i <= m; i++)
{
int q, x, y;
fin >> q >> x >> y;
if(q==0)
update(x, -y);
else
fout << ras(y) - ras(x - 1) << '\n';
}
}
