#include<stdio.h>
int main()
{
long q,s,x,y,i,j,c,p;
int r=2,b=1,a;
char C[2];
scanf("%ld",&q);
while(q–)
{
scanf("%s",C);
if(C[1]==105)
{
a=r;
r=b;
b=a;
continue;
}
else
{
scanf("%ld%ld",&x,&y);
s=1,i=1;
while(s<=x)
{
s=2s;
++i;
}
–i;
j=1,s=1;
while(s<=y)
{
s=2s;
++j;
}
–j;
c=1,p=i;
while(x!=y)
{
if(i>j)
{
x=x/2,–i,++c;
}
else if(i==j)
{
x=x/2,y=y/2;
–i,–j,c+=2;
}
else
{
y=y/2,–j,++c;
}
}
if(C[1]==98)
{
if(b==2)
{
if(p%2==0)
printf("%ld\n",c-c/2);
else
printf("%ld\n",c/2);
}
else
{
if(p%2==0)
printf("%ld\n",c/2);
else
printf("%ld\n",c-c/2);
}
}
else
{
if(r==2)
{
if(p%2==0)
printf("%ld\n",c-c/2);
else
printf("%ld\n",c/2);
}
else
{
if(p%2==0)
printf("%ld\n",c/2);
else
printf("%ld\n",c-c/2);
}
}
}
}
return 0;
}
1 Like
Please read this, before asking for help next time, or even better - read it and chnage your question, to make it easier get the answer quicklier 
It returns wrong answer for test cases from problem statement page - http://ideone.com/JjFRvT
Where are test cases on this page???I didn’t get them
On which page you meant? On ideone it is stdin
part…
@nitishchopra08 … look at the end of page, there you will see sections for stdin and stdout
gagaboy
7
can you help me figure out why this solution is wrong?
http://www.codechef.com/viewsolution/5423114
i used the bit method
@betlista man my code is for chef and red black tree and on http://ideone.com/JjFRvT input used is for chef and segment
My bad, sorry… I replaced the input with the one for red-black tree and still wrong output - 2
, can you help? Maybe I’m doing something wrong again.
For what inputs you got answer -2
You have to input like this
Qr 4 5
And then output will come
Thanx for taking pain but I need a little more help
It was not -2
(minus two), but two. One number 2 for 4 queries (you have to print result for each query) is not enough…
please tell me the test case you used
The one from problem statement page, try to replace c[2]
with c[5]
…
@betlista thanks a lot man.Submitted code successfully.
1 Like