Submission #729010

#TimeUsernameProblemLanguageResultExecution timeMemory
729010MilosMilutinovicStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
208 ms15556 KiB
/**
 *    author:  wxhtzdy
 *    created: 12.02.2023 12:01:44
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<int, bool> mp;
  vector<pair<int, int>> segs;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]]) {
      int s = 1;
      while (segs.back().first != a[i]) {
        mp[segs.back().first] = false;
        s += segs.back().second;
        segs.pop_back();
      }
      segs.back().second += s;
    } else {
      segs.emplace_back(a[i], 1);
      mp[a[i]] = true;
    }
  }
  for (auto& p : segs) {
    while (p.second > 0) {
      cout << p.first << '\n';
      p.second--;
    }
  }                                
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...