Nu aveti permisiuni pentru a descarca fisierul grader_test3.in
Cod sursa(job #2570527)
| Utilizator | Data | 4 martie 2020 17:24:00 | |
|---|---|---|---|
| Problema | Arbori indexati binar | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.95 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int v[100005];
int n, m;
void update(int add,int poz)
{
for(int i = poz; i <= n; i += i & (-i))
v[i] += add;
}
int query(int poz)
{
int sum = 0;
for(int i = poz; i >= 1; i -= i & (-i))
sum += v[i];
return sum;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= n; i ++)
{
int x;
fin >> x;
update(x,i);
}
for(int i = 1; i <= m; i ++)
{
int x, y, z;
fin >> x;
if(x == 0)
{
fin >> y >> z;
update(z,y);
}
else
if(x == 1)
{
fin >> y >> z;
fout << query(z) - query(y - 1) << '\n';
}
else
{
int a;
fin >> y >> z >> a;
}
}
return 0;
}
