제출 #916490

#제출 시각아이디문제언어결과실행 시간메모리
916490WJR_daggerStone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; //#define int long long #define endl "\n" #define pb push_back #define f first #define s second #define all(x) x.begin(), x.end() #define cout_line cout<<"line"<<__LINE__<<endl #define cout_val(x) cout<<#x<<": "<<x<<endl const long long mod=1e9+7; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n;cin>>n; int arr[n]={}; for(int i=0;i<n;i++) { cin>>arr[i]; } int l=0,r=0; set<int> cnt; while(r<n) { int val; while(1){ if(cnt.count(arr[r])==0) { cnt.insert(arr[r]); r++; } else{ val=arr[r]; break; } } int idx=r; for(l=r-1;l>=0;l--) { if(arr[l]==val){ while(arr[l-1]==val){ l--; } idx=l; break; } } for(int i=idx;i<r;i++) { cnt.erase(arr[i]); arr[i]=val; } r++; } for(int i:arr){ cout<<i<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...