Submission #916483

#TimeUsernameProblemLanguageResultExecution timeMemory
916483raypeng1729Stone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios::sync_with_stdio(false), cin.tie(0); int n; cin >> n; int a[n], id[n]; vector<int> v; for(int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for(int i = 0; i < n; i++) id[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin(); vector<vector<int>> pos(n); vector<int> to(n, -1); int cur = n, fin = 0; for(int i = 0; i < n; i++){ while(pos[id[i]].size() && pos[id[i]].back() < fin && pos[id[i]].back() > cur) pos[id[i]].pop_back(); if(pos[id[i]].size()) to[i] = pos[id[i]].back(), cur = to[i], fin = i; pos[id[i]].push_back(i); } for(int i = n - 1; i >= 0; i--){ if(to[i] == -1) continue; for(int j = i; j >= to[i]; j--) a[j] = a[i]; i = to[i]; } for(int i = 0; i < n; i++) cout << a[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...