ZhongJiaXuan

CF1883E - Look Back

Dec 14th, 2023
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. const int N = 1e5 + 10;
  5. int t, n, ans, Last;
  6. int Arr[N];
  7. int count(int x) { return log2(x) + 1; }
  8. signed main() {
  9.     ios::sync_with_stdio(false);
  10.     cin.tie(0);
  11.     cout.tie(0);
  12.     cin >> t;
  13.     while (t--) {
  14.         ans = Last = 0;
  15.         cin >> n;
  16.         for (int i = 1; i <= n; i++) cin >> Arr[i];
  17.         for (int i = 2; i <= n; i++) {
  18.             if (Arr[i] < Arr[i - 1]) { // 降序
  19.                 Last += ceil(log2(Arr[i - 1] * 1.0 / Arr[i]));
  20.                 Last = max(0LL, Last);
  21.                 ans += Last;
  22.             } else {
  23.                 Last -= (int)(log2(Arr[i] * 1.0 / Arr[i - 1]));
  24.                 Last = max(0LL, Last);
  25.                 ans += Last;
  26.             }
  27.         }
  28.         cout << ans << '\n';
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment