Submission #851004

#TimeUsernameProblemLanguageResultExecution timeMemory
851004arbuzickStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
345 ms39488 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } set<pair<pair<int, int>, int>> segms; map<int, vector<pair<int, int>>> vals; for (int i = 0; i < n; ++i) { if (vals[a[i]].empty()) { segms.insert({{i, i + 1}, a[i]}); vals[a[i]].push_back({i, i + 1}); } else { int start = vals[a[i]].back().first; while (!segms.empty() && segms.rbegin()->first.first >= start) { vals[segms.rbegin()->second].pop_back(); segms.erase(*segms.rbegin()); } segms.insert({{start, i + 1}, a[i]}); vals[a[i]].push_back({start, i + 1}); } } for (auto [lr, val] : segms) { for (int i = lr.first; i < lr.second; ++i) { cout << val << '\n'; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...