Cod sursa(job #2568899)
| Utilizator | Data | 4 martie 2020 10:21:19 | |
|---|---|---|---|
| Problema | Arbori indexati binar | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#define lsb(x) x & (-x)
#define Nmax 19894
using namespace std;
int aib[Nmax];
int v[Nmax], N;
void update(int pos, int x) {
for (int i = pos; i <= N; i += lsb(i))
aib[i] += x;
}
int query(int pos) {
int ans = 0;
for (int i = pos; i >= 1; i -= lsb(i))
ans += aib[i];
return ans;
}
int main()
{ N = 10;
update(5, 1);
update(4, -1);
cout << query(5) - query(4);
return 0;
}
