# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1125604 | salmon | Stone Arranging 2 (JOI23_ho_t1) | C++20 | 188 ms | 14164 KiB |
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> steck;
int h;
int lst[200100];
set<int> sat;
int main(){
scanf(" %d",&N);
for(int i = 0; i < N; i++){
scanf(" %d",&h);
lst[i] = h;
if(sat.find(h) != sat.end()){
while(!steck.empty() && lst[steck.back()] != h ){
sat.erase(lst[steck.back()]);
steck.pop_back();
}
steck.pop_back();
}
sat.insert(h);
steck.push_back(i);
}
vector<int> ans;
int c = lst[steck.back()];
for(int i = N - 1; i >= 0; i--){
if(!steck.empty() && i <= steck.back()){
c = lst[steck.back()];
steck.pop_back();
}
ans.push_back(c);
}
reverse(ans.begin(),ans.end());
for(int i : ans){
printf("%d\n",i);
}
}
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... |