//Siga Siga?! YES!
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int inf = 1e18,N = 3e3+1,MOD = 998244353;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> hmp;
void solve() {
int n;
cin >> n;
vi a(n+1);
for (int i=1;i<=n;i++) cin >> a[i];
hmp mp;
vi pq;
for (int i=1;i<=n;i++) {
while (!pq.empty() && mp.find(a[i])!=mp.end() && pq.back() > mp[a[i]]) {
mp.erase(a[pq.back()]);
pq.pop_back();
}
mp[a[i]] = i;
pq.push_back(i);
}
vi ans(n+1,0);
int ptr = n;
while (!pq.empty()) {
while (pq.back() <= ptr) ans[ptr--] = a[pq.back()];
pq.pop_back();
}
for (int i=1;i<=n;i++) cout << ans[i] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:14:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
14 | const int inf = 1e18,N = 3e3+1,MOD = 998244353;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |