传送门
桶排一下就好了
#include<iostream>
using namespace std;
const int N=2e3+10;
int tree[N];
int main()
{
int n,a,b;
cin>>n;
for(int i=1;i<=n;i++)
cin>>tree[i];
cin>>a>>b;
if(!tree[a])printf("ERROR: T[%d] is NULL",a);
else if(!tree[b])printf("ERROR: T[%d] is NULL",b);
else
{
while(a!=b)
{
if(a>b)a/=2;
else b/=2;
}
printf("%d %d",a,tree[a]);
}
}