Initially I am simply building the tree...(going up from x to the root via x's ancestors)
and then coming down I am calculating the value of every node till y. Can someone please point out the mistake in my code..
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;
long double a[1000010];
int main()
{
int tc;
cin>>tc;
while(tc--)
{
int x,y,w;
cin>>x>>y>>w;
if(x%2==0)
w*=2;
a[x]=w;
int i=x;
while(i/2>0)
{
if((i/2)%2==0)
{
if(i%2==0)
{
a[i/2]=a[i];
}
else
a[i/2]=2.0*a[i];
}
else
{
if(i%2==0)
{
a[i/2]=2.0*a[i];
}
else
a[i/2]=4.0*a[i];
}
i/=2;
}
i=1;
while(i<=y/2)
{
if(i%2)
{
a[2*i]=a[i]/2;
a[2*i + 1]=a[i]/4;
}
else
{
a[2*i]=a[i];
a[2*i+1]=a[i]/2;
}
i++;
}
cout<<fixed<<setprecision(6)<<a[y]<<endl;
}
}