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< tuple<int, int, int> > stk;
unordered_multiset<int> valInStk;
for (int x = 0; x < n; x++){
if (valInStk.find(arr[x]) != valInStk.end()){
int stopLoc = -1;
while (!stk.empty()){
if ( get<2>(stk.top()) == arr[x]){
stopLoc = get<0>(stk.top());
valInStk.erase(valInStk.find(get<2>(stk.top())));
stk.pop();
break;
}
else{
valInStk.erase(valInStk.find(get<2>(stk.top())));
stk.pop();
}
}
assert(stopLoc != -1);
stk.push({stopLoc, x, arr[x]});
valInStk.insert(arr[x]);
}
else{
stk.push({x, x, arr[x]});
valInStk.insert(arr[x]);
}
}
int res[n]; memset(res, -1, sizeof(res));
while (!stk.empty()){
auto tup = stk.top();
for (int y = get<0>(tup); y <= get<1>(tup); y++){
res[y] = get<2>(tup);
}
stk.pop();
}
for (int x = 0; x < n; x++) cout << res[x] << '\n';
}
Compilation message (stderr)
Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |