Cod sursa(job #1349712)
| Utilizator | Data | 20 februarie 2015 13:46:15 | |
|---|---|---|---|
| Problema | Arbori indexati binar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.71 kb |
#include <iostream>
#include <fstream>
#define N 100004
using namespace std;
int a[N];
void Update(int poz,int x)
{
while(poz<=n)
{
a[poz]+=x;
poz+=(poz & (-poz));
}
}
void Query(int poz)
{
int s;
while(poz>0)
{
s+=a[poz];
poz-=(poz & (-poz));
}
}
void Search(int x)
{
int st,dr,mij,sol,nr;
st=1;
dr=n;
while(st<=dr)
{
mij=(st+dr)/2;
nr=Query(mij);
if(x==nr)
{
sol=mij;
dr=mij-1;
}
else
if(nr<x) st=mij+1;
else dr=mij-1;
}
return sol;
}
int main()
{
cout << "Hello world!" << endl;
return 0;
}
