/ Randle /

记录详情

Wrong Answer

/in/foo.cc: In function 'int lowerbound(int)':
/in/foo.cc:24:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=l+r>>1;
           ~^~
/in/foo.cc: In function 'int lca(int, int)':
/in/foo.cc:36:7: warning: statement has no effect [-Wunused-value]
  deepy;
       ^
# 状态 耗时 内存占用
#1 Wrong Answer 4ms 380.0 KiB
#2 Wrong Answer 3ms 256.0 KiB
#3 Wrong Answer 3ms 376.0 KiB
#4 Wrong Answer 3ms 352.0 KiB
#5 Wrong Answer 3ms 352.0 KiB
#6 Wrong Answer 3ms 220.0 KiB
#7 Wrong Answer 6ms 384.0 KiB
#8 Wrong Answer 8ms 340.0 KiB
#9 Wrong Answer 8ms 340.0 KiB
#10 Wrong Answer 8ms 364.0 KiB

代码

#include<bits/stdc++.h>
inline void read(int &a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline void write(int a)
{
	if(a<0){putchar('-');a=-a;}
	if(a>9)write(a/10);
	putchar(a%10+'0');
}
int deep[31];
inline int lowerbound(int x)
{
	int l=0,r=30;
	while(l!=r)
	{
		int mid=l+r>>1;
		if(deep[mid]>=x)r=mid;
		else l=mid+1;
	}
	return l;
}
inline int lca(int x,int y)
{
	int k=0,deepx=lowerbound(x),deepy=lowerbound(y);
	if(deepx<deepy)std::swap(x,y);
	for(int i=1;i<=deepy-deepx;i++)x>>=1;
	if(x==y)return deepy-deepx;
	deepy;
	while(x!=y){k++;x>>=1;y>>=1;}
	return (k<<1)+deepy-deepx;
}
int main()
{
	int a=1,n;
	for(int i=0;i<=30;i++)
	{
		deep[i]=a;
		a<<=1;
	}
	read(n);int x,y;
	while(n--)
	{
		read(x);read(y);
		write(lca(x,y));printf("\n");
	}
	return 0;
}

信息

递交者
类型
递交
题目
三向城T1
题目数据
下载
语言
C++
递交时间
2017-11-07 14:35:44
评测时间
2017-11-07 14:35:44
评测机
分数
0
总耗时
55ms
峰值内存
384.0 KiB