Submission #855237

#TimeUsernameProblemLanguageResultExecution timeMemory
855237nsyStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
109 ms18988 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unordered_map <int, int> mp; stack <pair<int, pair<int, int>>> s; for (int i=0; i<n; i++) { int a; cin >> a; if (mp[a] == 0) { if (s.size() && s.top().first == a) { pair <int, pair<int, int>> p = s.top(); s.pop(); p.second.second++; s.push(p); } else { mp[a] = i+1; s.push({a, {i, i}}); } } else { while (s.size()) { if ((s.top()).second.first <= mp[a]-1 && (s.top().second.second) >= mp[a]-1) { pair <int, pair<int, int>> p = s.top(); s.pop(); p.second.second = i; s.push(p); break; } else { if (mp[(s.top()).first]-1 == (s.top()).second.first) mp[(s.top()).first]=0; s.pop(); } } } } vector <pair<int, pair<int, int>>> v; while (s.size()) { v.push_back(s.top()); s.pop(); } reverse(v.begin(), v.end()); for (auto it : v) { for (int i=it.second.first; i<=it.second.second; i++) { cout << it.first << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...