Submission #1188125

#TimeUsernameProblemLanguageResultExecution timeMemory
1188125yhx3Stone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
168 ms31980 KiB
#include <iostream> #include <bits/stdc++.h> #include <iomanip> #include <numeric> using namespace std; #define ll long long bool comp(const pair<ll,ll> &a,pair<ll,ll> &vl) { return a.second > vl.first; } bool scomp(const pair<ll,ll> &a,pair<ll,ll> &vl) { return a.first >= vl.first; } void solve() { int n; cin >> n; vector<int> a(n); map<int,set<int>> mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]].insert(i); } vector<int> ans(n); pair<int,int> oper = {-1,-1}; for (int i = 0; i < n; i++) { if (oper.first == -1 || oper.second < i) { oper = {-1,-1}; if (mp[a[i]].size() >= 2) { oper.first = a[i]; oper.second = *mp[a[i]].rbegin(); } ans[i] = a[i]; } else { ans[i] = oper.first; mp[a[i]].erase(i); } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << '\n'; } int main() { ios_base::sync_with_stdio(false); int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...