이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=2e5+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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |