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<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,y,a;
cin >> n;
vector<int> p(n);
vector<int> c(n);
map<int,bool> haha;
for(int i = 0; i < n; i++) {
cin >> a;
if(haha[a]) {
y = i-1;
while(y != -1 && c[y] != a) {
haha[c[y]] = false;
y = p[y];
}
if(y != -1) {
y = p[y];
}
p[i] = y;
}
else {
haha[a] = true;
p[i] = i-1;
}
c[i] = a;
}
y = n-1;
vector<int> ans(n);
while(y != -1) {
ans[y] = c[y];
y = p[y];
}
for(int i = n-1; i >= 0; i--) {
if(ans[i] == 0) {
ans[i] = ans[i+1];
}
}
for(int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |