제출 #780862

#제출 시각아이디문제언어결과실행 시간메모리
780862boris_mihovStone Arranging 2 (JOI23_ho_t1)C++17
0 / 100
4 ms1004 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> #include <stack> typedef long long llong; const int MAXN = 100000 + 10; const int INF = 1e9; int n; int a[MAXN]; bool wasThere[MAXN]; std::vector <std::pair <int,int>> st; std::stack <int> output; void solve() { for (int i = 1 ; i <= n ; ++i) { if (!wasThere[a[i]]) { wasThere[a[i]] = true; st.push_back({i, a[i]}); } else { while (st.back().second != a[i]) { wasThere[st.back().second] = false; st.pop_back(); } } } int ptr = n; while (!st.empty()) { while (ptr >= st.back().first) { output.push(st.back().second); ptr--; } st.pop_back(); } while (!output.empty()) { std::cout << output.top() << '\n'; output.pop(); } } void input() { std::cin >> n; for (int i = 1 ; i <= n ; ++i) { std::cin >> a[i]; } } void fastIOI() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIOI(); input(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...