Submission #729416

#TimeUsernameProblemLanguageResultExecution timeMemory
729416abcvuitunggioStone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
7 ms9740 KiB
#include <bits/stdc++.h> using namespace std; int n,a[200001],p[200001],r[200001],sz[200001]; vector <int> ve; set <int> s[200001]; int f(int i){ return (p[i]==i?i:p[i]=f(p[i])); } void unite(int i, int j){ i=f(i); j=f(j); if (sz[i]<sz[j]) swap(i,j); p[j]=i; sz[i]+=sz[j]; s[a[min(r[i],r[j])]].erase(min(r[i],r[j])); r[i]=max(r[i],r[j]); } int main(){ ios_base::sync_with_stdio(NULL);cin.tie(nullptr); cin >> n; for (int i=1;i<=n;i++){ cin >> a[i]; p[i]=r[i]=i; sz[i]=1; ve.push_back(a[i]); } sort(ve.begin(),ve.end()); ve.resize(unique(ve.begin(),ve.end())-ve.begin()); for (int i=1;i<=n;i++){ a[i]=lower_bound(ve.begin(),ve.end(),a[i])-ve.begin(); if (s[a[i]].empty()){ s[a[i]].insert(i); continue; } int j=*--s[a[i]].end(); while (j<i){ j=r[f(j)]; unite(j,j+1); j++; } } for (int i=1;i<=n;i++) cout << ve[a[r[f(i)]]] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...