#include <bits/stdc++.h>
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define F first
#define S second
#define pii(x, y) make_pair(x, y)
#define __builtin_popcount __builtin_popcountll
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define lg(x) (63 - __builtin_clz(x))
template <class X, class Y>
bool minimize(X &x, const Y &y)
{
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y)
{
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 6e5;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll oo = 2e18;
const double eps = 1e-1;
int n, a[N], st[4 * N], lz[4 * N];
vector<int> vi, ar[N];
void Input(void)
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i], vi.push_back(a[i]);
uni(vi);
for (int i = 1; i <= n; i ++) a[i] = lower_bound(all(vi), a[i]) - vi.begin() + 1;
}
void update(int u, int v, int vv, int id = 1, int l = 1, int r = n)
{
if (lz[id])
{
st[id] = lz[id];
if (l < r)
{
lz[id * 2] = lz[id];
lz[id * 2 + 1] = lz[id];
}
lz[id] = 0;
}
if (r < u || v < l) return ;
if (u <= l && r <= v)
{
st[id] = vv;
if (l < r)
{
lz[id * 2] = vv;
lz[id * 2 + 1] = vv;
}
return ;
}
int mid = (l + r) / 2;
update(u, v, vv, id * 2, l, mid);
update(u, v, vv, id * 2 + 1, mid + 1, r);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int pos, int id = 1, int l = 1, int r = n)
{
if (lz[id])
{
st[id] = lz[id];
if (l < r)
{
lz[id * 2] = lz[id];
lz[id * 2 + 1] = lz[id];
}
lz[id] = 0;
}
if (r < pos || pos < l) return 0;
if (l == r) return st[id];
int mid = (l + r) / 2;
return max(get(pos, id * 2, l, mid), get(pos, id * 2 + 1, mid + 1, r));
}
void solve(void)
{
set<int> st;
for (int i = 1; i <= n; i ++)
{
int L = i;
if (sz(ar[a[i]])) L = ar[a[i]].back() + 1;
update(L, i, a[i]);
while (sz(st))
{
auto itr = --st.end();
int k = a[*itr];
if (*itr >= L)
{
st.erase(itr);
ar[k].pop_back();
if (sz(ar[k])) st.insert(ar[k].back());
}
else break;
}
if (sz(ar[a[i]])) st.erase(ar[a[i]].back());
ar[a[i]].push_back(i);
st.insert(i);
}
for (int i = 1; i <= n; i ++) cout << vi[get(i) - 1] << '\n';
}
int main()
{
std::ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("CLASSROOM.inp", "r", stdin);
// freopen("CLASSROOM.out", "w", stdout);
int test = 1;
//cin >> test;
while (test --)
{
Input();
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5060 KB |
Output is correct |
7 |
Correct |
2 ms |
4960 KB |
Output is correct |
8 |
Correct |
3 ms |
5024 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5024 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
5036 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5068 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5028 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
6 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
5076 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
5032 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
4 ms |
5076 KB |
Output is correct |
12 |
Correct |
4 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5032 KB |
Output is correct |
16 |
Correct |
3 ms |
5012 KB |
Output is correct |
17 |
Correct |
86 ms |
10304 KB |
Output is correct |
18 |
Correct |
84 ms |
10256 KB |
Output is correct |
19 |
Correct |
93 ms |
12104 KB |
Output is correct |
20 |
Correct |
101 ms |
12248 KB |
Output is correct |
21 |
Correct |
93 ms |
12076 KB |
Output is correct |
22 |
Correct |
93 ms |
12088 KB |
Output is correct |
23 |
Correct |
93 ms |
12056 KB |
Output is correct |
24 |
Correct |
92 ms |
12088 KB |
Output is correct |
25 |
Correct |
94 ms |
12128 KB |
Output is correct |
26 |
Correct |
95 ms |
12104 KB |
Output is correct |
27 |
Correct |
94 ms |
12072 KB |
Output is correct |
28 |
Correct |
93 ms |
12148 KB |
Output is correct |
29 |
Correct |
87 ms |
11308 KB |
Output is correct |
30 |
Correct |
88 ms |
10308 KB |
Output is correct |
31 |
Correct |
86 ms |
10252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5060 KB |
Output is correct |
7 |
Correct |
2 ms |
4960 KB |
Output is correct |
8 |
Correct |
3 ms |
5024 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Correct |
3 ms |
5024 KB |
Output is correct |
15 |
Correct |
3 ms |
5076 KB |
Output is correct |
16 |
Correct |
3 ms |
5024 KB |
Output is correct |
17 |
Correct |
4 ms |
5204 KB |
Output is correct |
18 |
Correct |
3 ms |
5204 KB |
Output is correct |
19 |
Correct |
3 ms |
5036 KB |
Output is correct |
20 |
Correct |
3 ms |
5036 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5076 KB |
Output is correct |
25 |
Correct |
3 ms |
5068 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
3 ms |
5028 KB |
Output is correct |
29 |
Correct |
3 ms |
5204 KB |
Output is correct |
30 |
Correct |
6 ms |
5204 KB |
Output is correct |
31 |
Correct |
2 ms |
4948 KB |
Output is correct |
32 |
Correct |
2 ms |
4948 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
5076 KB |
Output is correct |
36 |
Correct |
2 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
5032 KB |
Output is correct |
40 |
Correct |
3 ms |
5076 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5076 KB |
Output is correct |
43 |
Correct |
3 ms |
5076 KB |
Output is correct |
44 |
Correct |
3 ms |
5076 KB |
Output is correct |
45 |
Correct |
3 ms |
5032 KB |
Output is correct |
46 |
Correct |
3 ms |
5012 KB |
Output is correct |
47 |
Correct |
86 ms |
10304 KB |
Output is correct |
48 |
Correct |
84 ms |
10256 KB |
Output is correct |
49 |
Correct |
93 ms |
12104 KB |
Output is correct |
50 |
Correct |
101 ms |
12248 KB |
Output is correct |
51 |
Correct |
93 ms |
12076 KB |
Output is correct |
52 |
Correct |
93 ms |
12088 KB |
Output is correct |
53 |
Correct |
93 ms |
12056 KB |
Output is correct |
54 |
Correct |
92 ms |
12088 KB |
Output is correct |
55 |
Correct |
94 ms |
12128 KB |
Output is correct |
56 |
Correct |
95 ms |
12104 KB |
Output is correct |
57 |
Correct |
94 ms |
12072 KB |
Output is correct |
58 |
Correct |
93 ms |
12148 KB |
Output is correct |
59 |
Correct |
87 ms |
11308 KB |
Output is correct |
60 |
Correct |
88 ms |
10308 KB |
Output is correct |
61 |
Correct |
86 ms |
10252 KB |
Output is correct |
62 |
Correct |
93 ms |
13448 KB |
Output is correct |
63 |
Correct |
181 ms |
22988 KB |
Output is correct |
64 |
Correct |
171 ms |
23320 KB |
Output is correct |
65 |
Correct |
105 ms |
14996 KB |
Output is correct |
66 |
Correct |
103 ms |
14876 KB |
Output is correct |
67 |
Correct |
108 ms |
15508 KB |
Output is correct |
68 |
Correct |
109 ms |
15272 KB |
Output is correct |
69 |
Correct |
110 ms |
15240 KB |
Output is correct |
70 |
Correct |
109 ms |
15212 KB |
Output is correct |
71 |
Correct |
106 ms |
15264 KB |
Output is correct |
72 |
Correct |
113 ms |
15160 KB |
Output is correct |
73 |
Correct |
184 ms |
21268 KB |
Output is correct |
74 |
Correct |
204 ms |
22468 KB |
Output is correct |
75 |
Correct |
174 ms |
28204 KB |
Output is correct |
76 |
Correct |
182 ms |
30284 KB |
Output is correct |
77 |
Correct |
179 ms |
28188 KB |
Output is correct |
78 |
Correct |
199 ms |
28228 KB |
Output is correct |