# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
757628 | mdub | Stone Arranging 2 (JOI23_ho_t1) | C++14 | 1 ms | 340 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>
using namespace std;
int main () {
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<pair<int, int>> bornes(n, {0, -1});
vector<set<int>> js(n);
for (int i = 0; i < n; i++) {
//cout << a[i] << endl;
if (js[a[i]].size()) {
auto it = js[a[i]].end();
it--;
int ind = *it;
while (ind < i) {
if (bornes[ind].first > 0) {
ind = bornes[ind].second;
js[-bornes[ind].first].erase(bornes[ind].second);
}
else {
js[a[ind]].erase(ind);
}
ind++;
}
bornes[*it].first = a[i];
bornes[*it].second = i;
bornes[i].first = -a[i];
bornes[i].second = i;
}
js[a[i]].insert(i);
}
int cur = -1;
for (int i = 0; i < bornes.size(); i++) {
pair<int, int> elem = bornes[i];
if (elem.first > 0 && cur == -1) {
cur = elem.first;
}
if (cur == -1) {
cout << a[i] << '\n';
}
else cout << cur << '\n';
if (elem.first == -cur) cur = -1;
}
}
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... |