Submission #807712

#TimeUsernameProblemLanguageResultExecution timeMemory
807712dong_liuStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
74 ms9044 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), c; for (int i = 0; i < n; i++) cin >> a[i]; c = a; sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); for (int i = 0; i < n; i++) a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin(); vector<int> has(c.size()); vector<array<int, 3>> segs; for (int i = 0; i < n; i++) { if (!has[a[i]]) segs.push_back({i, i, a[i]}); else { while (segs.back()[2] != a[i]) { has[segs.back()[2]] = 0; segs.pop_back(); } segs.back()[1] = i; } has[a[i]] = 1; } for (auto [l, r, p] : segs) for (int i = l; i <= r; i++) a[i] = c[p]; for (int i = 0; i < n; i++) cout << a[i] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...