Submission #1135494

#TimeUsernameProblemLanguageResultExecution timeMemory
1135494UnforgettableplStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
302 ms157316 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef double ld; const int INF = 1e10; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> arr(n); for(int&i:arr)cin>>i; set<int> arrnew; map<int,stack<int>> idx; for(int i=0;i<n;i++) { while(!idx[arr[i]].empty()) { if(!arrnew.contains(idx[arr[i]].top())) { idx[arr[i]].pop(); continue; } while(*--arrnew.end()>idx[arr[i]].top())arrnew.erase(--arrnew.end()); break; } idx[arr[i]].emplace(i+1); arrnew.insert(i+1); } auto iter = arrnew.begin(); int col = -1; for(int i=1;i<=n;i++) { if(iter!=arrnew.end() and *iter==i){col=arr[i-1];iter++;} cout << col << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...