Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("03")
- #define _CRT_SECURE_NO_WARNINGS
- #include "bits/stdc++.h"
- using namespace std;
- using namespace chrono;
- #define all(a) a.begin(), a.end()
- #define allr(a) a.rbegin(), a.rend()
- #define endl "\n"
- #define fast_io ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
- mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
- typedef long long ll;
- typedef long double ld;
- ll run(vector<ll> &a,ll n) {
- ll ans = 0, k = 1;
- for (ll i = n - 2; i >= 0; i--) {
- if (a[i] == a[n - 1]) {
- k++;
- }
- else {
- i -= k - 1;
- k *= 2;
- ans++;
- }
- }
- return ans;
- }
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- srand(time(NULL));
- ll t = 1;
- //cin >> t;
- while (1) {
- ll n = rand()%200+1;
- // cin >> n;ll n;
- vector<ll> a(n);
- if (n == 1)continue;
- for (ll i = 0; i < n; i++) {
- a[i] = rnd() % 200;
- }
- reverse(all(a));
- deque<ll> m;
- for (ll i = 0; i < n; i++) {
- m.push_back(a[i]);
- }
- ll fix = a[0];
- ll cnt = 0;
- ll k = 0;
- while (!m.empty()) {
- while (!m.empty() && fix == m.front()) {
- m.pop_front();
- k++;
- }
- ll d = 0;
- bool fl = false;
- while (!m.empty() && d < k) {
- m.pop_front();
- d++;
- fl = true;
- }
- k += k;
- cnt += fl;
- }
- reverse(all(a));
- if (cnt != run(a, n)) {
- for (ll i = 0; i < n; i++) {
- cout << a[i] << ' ';
- }
- cout << endl;
- cout << cnt << ' ' << run(a, n);
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement