Submission #942384

#TimeUsernameProblemLanguageResultExecution timeMemory
942384tnknguyen_Stone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
441 ms687740 KiB
/** * @file main.cpp * @author tnknguyen_ ([email protected]) * @date 07-03-2024 * * @copyright Copyright (c) 2024 * https://oj.uz/problem/view/JOI23_ho_t1 */ #include <bits/stdc++.h> using namespace std; #define endl '\n' const int sz = 1e6 + 5; vector<int> b; stack<int> pos[sz]; int a[sz], ans[sz]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("main.inp","r",stdin); //freopen("main.out","w",stdout); int n; cin>>n; for(int i=1;i<=n;++i){ cin>>a[i]; b.push_back(a[i]); } sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); for(int i=1;i<=n;++i){ a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1; } stack<int> st; for(int i=1;i<=n;++i){ while(pos[a[i]].size() && st.size() && st.top() > pos[a[i]].top()){ pos[a[st.top()]].pop(); st.pop(); } st.push(i); pos[a[i]].push(i); } while(st.size()){ ans[st.top()] = a[st.top()]; st.pop(); } int val = a[1]; for(int i=1;i<=n;++i){ if(ans[i]){ val = b[ans[i] - 1]; } cout<<val<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...