E题

#include <bits/stdc++.h>
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
typedef long long LL;
const int N = 1e5 + 10, M = N, mod = 1e9 + 7;
using namespace std;
LL a[N], b[N];
int n;
int main()
{
    CLOSE;
    int T;
    cin >> T;
    while(T --){
        cin >> n;
        for(int i = 1; i <= n; i ++){
            cin >> a[i];
            b[i] = 0;
        }
        LL cnt = 0;
        for(int i = 2; i <= n; i ++){
        	//
            if(a[i] < a[i - 1]){
                b[i] = max(0ll, b[i - 1] + (LL)ceil(log2((double)a[i - 1] / (double)a[i])));
            } else{
                b[i] = max(0ll, b[i - 1] - (LL)floor(log2((double)a[i] / (double)a[i - 1])));
            }
            cnt += b[i];
        }
        cout << cnt << endl;
    }
    return 0;
}
posted @ 2024-02-05 16:32  可爱的卤蛋  阅读(12)  评论(1编辑  收藏  举报