이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//cf meowcneil; t.me/macneilbot
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <random>
#include <cassert>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f(a) for(int i = 0; i<a; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<str> vestr;
typedef vector<int> vei;
typedef vector<vector<int>> veve;
void solve() {
int n;
cin >> n;
deque<pair<int, int>> au;
map<int, int> ct;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (ct[x] > 0) {
int C = 1;
while (au.back().first != x) {
ct[au.back().first] -= au.back().second;
C += au.back().second;
au.pop_back();
}
au.back().second += C;
continue;
}
au.push_back({x, 1});
ct[x]++;
}
for (auto e : au) {
for (int i = 0; i < e.second; ++i) {
cout << e.first << '\n';
}
}
}
signed main() {
int tc = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
// cin >> tc;
#else
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// cin >> tc;
#endif
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |