제출 #1078351

#제출 시각아이디문제언어결과실행 시간메모리
1078351lftroqStone Arranging 2 (JOI23_ho_t1)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> #define endl '\n' #define fi first #define se second using namespace std; typedef long long ll; const int N=200005; int a[N],b[N]; void solve() { int n; cin >> n; map<int,vector<int>> m; for(int i=1,l=0,r=0;i<=n;i++) { cin >> a[i]; int x=a[i]; if(m[x].size()) { if(m[x].back()>=r) { l=m[x].back();r=i; b[l]=r; } else if(m[x][0]<l) { int y=lower_bound(m[x].begin(),m[x].end(),l)-m[x].begin(); y--; l=m[x][y],r=i; b[l]=r; } } m[x].push_back(i); } int temp=0; for(int i=1;i<=n;i++) { if(!temp) temp=max(temp,b[i]); if(temp==i) temp=0; if(!temp) cout << a[i] << ' '; else cout << a[temp] << ' '; } } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...