Submission #1281763

#TimeUsernameProblemLanguageResultExecution timeMemory
1281763muhammad-ahmadStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
363 ms163676 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' void solve(){ int n, c = 0; cin >> n; int a[n + 1] = {}; map<int, int> val, rev; for (int i = 1; i <= n; i++){ cin >> a[i]; if (val[a[i]]) a[i] = val[a[i]]; else { val[a[i]] = ++c; rev[c] = a[i]; a[i] = val[a[i]]; } } deque<int> idx[n + 1] = {}; for (int i = 1; i <= n; i++) idx[a[i]].push_back(i); for (int i = 1; i <= n; i++){ while (idx[a[i]].size() && idx[a[i]].front() <= i) idx[a[i]].pop_front(); if (idx[a[i]].empty()){ continue; // cout << i << ' ' << 'H' << endl; } int j = idx[a[i]].front(); // cout << j << endl; for (int k = i; k <= j; k++){ a[k] = a[i]; } i = j - 1; } for (int i = 1; i <= n; i++) cout << rev[a[i]] << endl; // cout << endl; } signed main(){ int tc = 1; // cin >> tc; while (tc--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...