//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;
struct chash {
// any random-ish large odd number will do
const uint64_t C = 6e18 + 71;
// random 32-bit number
const uint32_t RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
size_t operator()(uint64_t x) const {
// see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
return __builtin_bswap64((x ^ RANDOM) * C);
}
};
typedef gp_hash_table<int, int, chash> hmp;
const int BUF_SZ=1<<20;
char buf[BUF_SZ];
int pos;
int len;
inline char next_char() {
if (pos == len) {
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, stdin);
}
return buf[pos++];
}
inline int read_int() {
int x;
char ch=next_char();
while(ch<'0'||'9'<ch)ch=next_char();
x = ch - '0';
while (isdigit(ch = next_char())) { x = x * 10 + (ch - '0'); }
return x;
}
char out[BUF_SZ];
int curind=0;
inline void flush(){
fwrite(out,1,curind,stdout);
curind=0;
}
inline void putchar(char c){
out[curind++]=c;
if(curind==BUF_SZ)flush();
}
char temp[10];
inline void putuint(int i){
int lll=0;
while(i){
temp[lll++]=(i%10)+'0';
i/=10;
}
while(lll){
putchar(temp[--lll]);
}
}
void solve() {
int n;
n = read_int();
vi a(n+1);
for (int i=1;i<=n;i++) {
a[i] = read_int();
}
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++) {
putuint(ans[i]);
putchar('\n');
}
flush();
}
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... |