原题链接https://www.luogu.com.cn/problem/P8681
了解完全二叉树的性质
注意可能最后一层没有满
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#include <vector>
#define ll long long
const ll N = 1e5 + 10;
//ll n,m;
//ll op[N];
void solve(){
ll n;
std::cin >> n;
std::vector<ll> op(n + 1);
for(ll i = 1; i <= n; i ++){
std::cin >> op[i];
op[i] += op[i - 1];
}
ll kk = 1;
ll res = 0;
ll mxx = -1;
ll ans = -1;
ll uu = 0;
while(res < n){
uu ++;
// std::cout << op[res + kk] - op[res] << "\n";
if(mxx < op[std::min(res + kk,n)] - op[res]){
ans = uu;
}
mxx = std::max(mxx,op[std::min(res + kk,n)] - op[res]);
res += kk;
kk *= 2;
}
std::cout << ans << "\n";
return ;
}
int main(){
ll t = 1;
while(t --)
solve();
return 0;
}