# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990881 | tincamatei | Stone Arranging 2 (JOI23_ho_t1) | C++14 | 143 ms | 14528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
int main() {
std::cin.tie(NULL);
std::iostream::sync_with_stdio(false);
int N;
std::map<int, int> last_pos;
std::vector<std::pair<int, int>> st;
std::cin >> N;
for (int i = 1; i <= N; i++) {
int val;
std::cin >> val;
int last = i;
if (last_pos[val] != 0)
last = last_pos[val];
while (!st.empty() && st.back().first >= last) {
last_pos[st.back().second] = 0;
st.pop_back();
}
st.push_back({last, val});
last_pos[val] = i;
}
std::vector<int> res(1 + N);
int last = N;
for (int t = (int)st.size() - 1; t >= 0; t--) {
auto [first, val] = st[t];
while (last >= first) {
res[last] = val;
last--;
}
}
for (int i = 1; i <= N; i++)
std::cout << res[i] << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |