# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
799061 | acatmeowmeow | Stone Arranging 2 (JOI23_ho_t1) | C++11 | 1 ms | 328 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;
#define int long long
const int N = 2e5;
int n, arr[N + 5], res[N + 5];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >>n;
for (int i = 1; i <= n; i++) cin >> arr[i];
multiset<int> st;
vector<int> cnt;
for (int i = 1; i <= n; i++) {
if (st.find(arr[i]) == st.end()) cnt.push_back(i);
else {
while (cnt.size() && arr[cnt.back()] != arr[i]) st.erase(st.find(arr[cnt.back()])), cnt.pop_back();
cnt.push_back(i);
}
st.insert(arr[i]);
}
int index = 0;
while (index < cnt.size()) {
if(index + 1 < cnt.size() && arr[cnt[index]] == arr[cnt[index + 1]]) {
for (int i = cnt[index]; i <= cnt[index + 1]; i++) res[i] = arr[cnt[index]];
index += 2;
} else {
res[cnt[index]] = arr[cnt[index]];
index++;
}
}
for (int i = 1; i <= n; i++) 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... |