Submission #924120

#TimeUsernameProblemLanguageResultExecution timeMemory
924120vjudge1Stone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
1 ms600 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fst first #define snd second #define pb push_back #define forn(i,a,b) for(int i = a; i < b; i++) #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define mset(a,v) memset((a),(v),sizeof(a)) #define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n'; #define pi pair<int,int> #define pll pair<ll,ll> typedef long long ll; using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset; int main(){ ll n; cin>>n; vector<ll> data(n); vector<ll> color(n); map<ll,ll> compress; forn(i,0,n) cin>>data[i]; forn(i,0,n) compress[data[i]]=1; int indice = 1; for(auto i:compress) compress[i.fst]=indice, indice++; forn(i,0,n) color[i]=compress[data[i]]; vector<ll> lastValue(n+1,-1); set< pair<ll,ll> > position; forn(i,0,n){ if(lastValue[color[i]]!=-1){ auto it = position.lower_bound({lastValue[color[i]],color[i]}); if((*it).fst==lastValue[color[i]]){ while(it!=position.end()){ //cout<<(*it).fst<<"-+-+-"<<(*it).snd<<'\n'; auto newIt = it; newIt++; position.erase(it); it=newIt; } } } lastValue[color[i]]=i; position.insert({i,color[i]}); /*for(auto it:position) cout<<it.fst<<" "<<it.snd<<'\n'; cout<<"----------------\n";*/ } /*cout<<SZ(position)<<'\n'; for(auto it:position) cout<<it.fst<<" "<<it.snd<<'\n';*/ vector<ll> res; auto it = position.end(); it--; auto newIt = it; newIt--; while(it!=position.begin()){ /*cout<<(*it).fst<<" "<<(*it).snd<<'\n'; cout<<(*newIt).fst<<" "<<(*newIt).snd<<'\n'; cout<<"-------------------\n";*/ forn(i,(*newIt).fst,(*it).fst){ res.pb((*it).snd); } it=newIt; newIt=it; newIt--; } //cout<<"Procesamiento Terminado\n"; forn(i,0,(*position.begin()).fst+1){ res.pb((*position.begin()).snd); } reverse(ALL(res)); forn(i,0,SZ(res)) cout<<res[i]<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...