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 <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
// 入力
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
// å„色ã«å¯¾ã—ã¦ã€Œæœ€ã‚‚å³ã®ä½ç½®ã€ã‚’å‰è¨ˆç®—
map<int, int> rightmost;
for (int i = 0; i < N; i++) {
rightmost[A[i]] = max(rightmost[A[i]], i);
}
// å¡—ã£ã¦ã„ã
vector<int> answer(N);
int curpos = 0;
while (curpos != N) {
int nextpos = rightmost[A[curpos]] + 1;
for (int i = curpos; i < nextpos; i++) {
answer[i] = A[curpos];
}
curpos = nextpos;
}
// 出力
for (int i = 0; i < N; i++) {
cout << answer[i] << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |