#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i];
}
map<int, int> mp;
vector<int> p(n + 1);
for (int i = 1; i <= n; i++){
if (mp.find(a[i]) != mp.end()){
p[i] = mp[a[i]];
}
mp[a[i]] = i;
}
int r = 0, c = 0;
for (int i = 1; i <= n; i++){
if (p[i] > r || a[i] == c){
for (int j = max(r, p[i]); j < i; j++){
a[j] = a[i];
}
r = i;
c = a[i];
}
}
for (int i = 1; i <= n; i++){
cout<<a[i]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |