Submission #916475

#TimeUsernameProblemLanguageResultExecution timeMemory
916475GrandTiger1729Stone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
181 ms20808 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } map<int, pair<int, int>> mp; vector<pair<int, pair<int, int>>> stk; vector<int> ans(n); for (int i = 0; i < n; i++) { if (mp.find(a[i]) != mp.end()) { while (a[i] != stk.back().first) { mp.erase(stk.back().first); stk.pop_back(); } stk.back().second.second = i; mp[a[i]].second = i; } else { mp[a[i]] = make_pair(i, i); stk.emplace_back(a[i], make_pair(i, i)); } } for (auto &[c, pp] : mp) { auto &[l, r] = pp; for (int i = l; i <= r; i++) { ans[i] = c; } } for (int i = 0; i < n; i++) { cout << ans[i] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...