This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <map>
using namespace std;
int a[200005], t[1000005], lazy[1000005];
map<int, int> c;
void push(int v) {
if (lazy[v] != 0) {
t[v * 2] = t[v * 2 + 1] = lazy[v];
lazy[v * 2] = lazy[v * 2 + 1] = lazy[v];
lazy[v] = 0;
}
}
void update(int v, int tl, int tr, int l, int r, int x) {
if (l > r) return;
if (tl == l && tr == r) {
t[v] = x;
lazy[v] = x;
return;
}
push(v);
int mid = (tl + tr) / 2;
update(v * 2, tl, mid, l, min(r, mid), x);
update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
}
int sum(int v, int tl, int tr, int x) {
if (tl == tr) {
return t[v];
}
push(v);
int mid = (tl + tr) / 2;
if (mid >= x) return sum(v * 2, tl, mid, x);
return sum(v * 2 + 1, mid + 1, tr, x);
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int k;
if (c[a[i]] != 0) k = sum(1, 1, n, c[a[i]]);
if (c[a[i]] == 0 || (k != a[i] && k != 0)) c[a[i]] = i;
else {
int h = c[a[i]];
c[a[i]] = i;
update(1, 1, n, h, i, a[i]);
}
}
for (int i = 1; i <= n; i++) {
int k = sum(1, 1, n, i);
if (k == 0) k = a[i];
cout << k << endl;
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:41:26: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
41 | if (c[a[i]] == 0 || (k != a[i] && k != 0)) c[a[i]] = i;
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |