Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- const int N = 1e5 + 10;
- int t, n, ans, Last;
- int Arr[N];
- int count(int x) { return log2(x) + 1; }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> t;
- while (t--) {
- ans = Last = 0;
- cin >> n;
- for (int i = 1; i <= n; i++) cin >> Arr[i];
- for (int i = 2; i <= n; i++) {
- if (Arr[i] < Arr[i - 1]) { // 降序
- Last += ceil(log2(Arr[i - 1] * 1.0 / Arr[i]));
- Last = max(0LL, Last);
- ans += Last;
- } else {
- Last -= (int)(log2(Arr[i] * 1.0 / Arr[i - 1]));
- Last = max(0LL, Last);
- ans += Last;
- }
- }
- cout << ans << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment