제출 #998165

#제출 시각아이디문제언어결과실행 시간메모리
998165dimashhhStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
197 ms34148 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 3e5 + 30, MOD = 1e9 + 7; int n,a[N],l[N],b[N]; map<int,set<int>> mp; void test(){ cin >> n; for(int i = 1;i <= n;i++){ cin >> a[i]; } vector<int> pos; for(int i = 1;i <= n;i++){ if(mp.count(a[i])){ if(!mp[a[i]].empty()){ int lst = (*mp[a[i]].rbegin()); while((int)pos.size() && pos.back() >= lst){ mp[a[pos.back()]].erase(pos.back()); pos.pop_back(); } } } pos.push_back(i); mp[a[i]].insert(i); } int prev = 0; for(int i = 0;i < (int)pos.size();i++){ for(int j = prev + 1;j < pos[i];j++){ a[j] = a[pos[i]]; } prev = pos[i]; } for(int i = 1;i <= n;i++){ cout << a[i] << '\n'; } } int main() { ios_base::sync_with_stdio(false);cin.tie(0); int t = 1; // cin >> t; while(t--){ test(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...