根据二叉树的性质,运用双指针
#include<iostream>
#define N 100010
using namespace std;
typedef long long LL;
int main()
{
int n,q[N];
scanf("%d",&n);
for(int i = 1;i <= n;i ++) scanf("%d",&q[i]);
LL maxs = -1e18;
int depth = 0;
for(int d = 1, i = 1;i <= n;d ++ , i *= 2)//d表示深度,i表示每一层的起点
{
LL s = 0;
for(int j = i;j < i + (1 << d - 1) && j <= n;j ++)
s += q[j];
if(s > maxs)
{
maxs = s;
depth = d;
}
}
printf("%d\n",depth);
}