Advertisement
ivnikkk

Untitled

Jan 27th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #pragma GCC optimize("03")
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. using namespace chrono;
  6. #define all(a) a.begin(), a.end()
  7. #define allr(a) a.rbegin(), a.rend()
  8. #define endl "\n"
  9. #define fast_io ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  10. mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
  11. typedef long long ll;
  12. typedef long double ld;
  13.  
  14. ll run(vector<ll> &a,ll n) {
  15.     ll ans = 0, k = 1;
  16.     for (ll i = n - 2; i >= 0; i--) {
  17.         if (a[i] == a[n - 1]) {
  18.             k++;
  19.         }
  20.         else {
  21.             i -= k - 1;
  22.             k *= 2;
  23.             ans++;
  24.         }
  25.     }
  26.     return ans;
  27. }
  28. signed main() {
  29. #ifdef _DEBUG
  30.     freopen("input.txt", "r", stdin);
  31.     freopen("output.txt", "w", stdout);
  32. #endif
  33.     srand(time(NULL));
  34.     ll t = 1;
  35.     //cin >> t;
  36.     while (1) {
  37.         ll n = rand()%200+1;
  38.        // cin >> n;ll n;
  39.         vector<ll> a(n);
  40.         if (n == 1)continue;
  41.         for (ll i = 0; i < n; i++) {
  42.             a[i] = rnd() % 200;
  43.         }
  44.         reverse(all(a));
  45.         deque<ll> m;
  46.         for (ll i = 0; i < n; i++) {
  47.             m.push_back(a[i]);
  48.         }
  49.         ll fix = a[0];
  50.         ll cnt = 0;
  51.         ll k = 0;
  52.         while (!m.empty()) {
  53.             while (!m.empty() && fix == m.front()) {
  54.                 m.pop_front();
  55.                 k++;
  56.             }
  57.             ll d = 0;
  58.             bool fl = false;
  59.             while (!m.empty() && d < k) {
  60.                 m.pop_front();
  61.                 d++;
  62.                 fl = true;
  63.             }
  64.             k += k;
  65.             cnt += fl;
  66.         }
  67.         reverse(all(a));
  68.         if (cnt != run(a, n)) {
  69.             for (ll i = 0; i < n; i++) {
  70.                 cout << a[i] << ' ';
  71.             }
  72.             cout << endl;
  73.             cout << cnt << ' ' << run(a, n);
  74.             return 0;
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement