# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941387 | shoryu386 | Stone Arranging 2 (JOI23_ho_t1) | C++17 | 52 ms | 14976 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
main(){
int n; cin >> n;
int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
stack<int> stk;
unordered_multiset<int> valInStk;
int res[n];
for (int x = 0; x < n; x++){
res[x] = arr[x];
if (valInStk.find(res[x]) != valInStk.end()){
vector<int> items;
while (!stk.empty()){
if ( res[stk.top()] == res[x]){
break;
}
else{
items.push_back(stk.top());
valInStk.erase(valInStk.find(res[stk.top()]));
stk.pop();
}
}
for (auto y : items){
res[y] = res[x];
}
}
stk.push(x);
valInStk.insert(res[x]);
}
for (int x = 0; x < n; x++) cout << res[x] << '\n';
}
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... |