제출 #833010

#제출 시각아이디문제언어결과실행 시간메모리
833010beepbeepsheepStone Arranging 2 (JOI23_ho_t1)C++17
25 / 100
9 ms3932 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 tree<long long, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define ii pair<ll,ll> #ifndef DEBUG #define cerr if (0) cerr #define endl '\n' #endif const ll inf=1e15; const ll maxn=1e5+5; const ll mod=1e9+7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<ii> v; ll par[maxn]; ll ans[maxn]; map<ll,ll> where; ll root(ll x){ if (par[x]==x) return x; return par[x]=root(par[x]); } void connect(ll a, ll b){ a=root(a),b=root(b); if (a==b) return; par[a]=b; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,ele; cin>>n; for (int i=0;i<maxn;i++) par[i]=i; for (int i=1;i<=n;i++){ cin>>ele; if (where.find(ele)==where.end()) where[ele]=-1; cerr<<where[ele]<<endl; v.emplace_back(i,ele); ans[i]=ele; if (where[ele]!=-1){ while (v.back().first!=where[ele]){ connect(v.back().first,where[ele]); if (where[v.back().second]==v.back().first) where[v.back().second]=-1; v.pop_back(); } } if (where[ele]==-1) where[ele]=i; } for (int i=1;i<=n;i++) cout<<ans[root(i)]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...