제출 #785282

#제출 시각아이디문제언어결과실행 시간메모리
785282KLPPStone Arranging 2 (JOI23_ho_t1)C++14
100 / 100
138 ms15960 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int lld; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; #define rep(i,a,b) for(int i=a;i<b;i++) #define trav(a,v) for(auto a:v) void solve(){ int n; cin>>n; vector<pair<int,int> > V; set<int> S; rep(i,0,n){ int x; cin>>x; if(V.size()==0){ V.push_back({x,i}); S.insert(x); }else{ while(S.find(x)!=S.end()){ S.erase(V[V.size()-1].first); V.pop_back(); } V.push_back({x,i}); S.insert(x); } } vector<int> ans(n,-1); int last=-1; rep(i,0,(int)V.size()){ rep(j,last+1,V[i].second+1){ ans[j]=V[i].first; } last=V[i].second; } trav(a,ans)cout<<a<<"\n"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int tt=1; //cin>>tt; while(tt--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...