//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct node {
int color;
pair<int,int> sect;
node() = default;
node(int val,int l,int r) : color(val), sect(l,r) {}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector <int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec[i];
}
vector <int> all_sect;
map <int,vector <pair<int,int>>> mp;
for (int i = 0;i < n;i++) {
if (mp[vec[i]].size() == 0) {
all_sect.push_back(vec[i]);
mp[vec[i]].push_back(pair<int,int>(i,i));
}else {
while (all_sect.back() != vec[i]) {
mp[all_sect.back()].pop_back();
all_sect.pop_back();
}
mp[all_sect.back()].back().second = i;
}
}
vector <int> ans(n);
for (auto el : mp) {
for (auto i :el.second) {
for (int j = i.first;j <= i.second;j++) {
ans[j] = el.first;
}
}
}
for (auto el : ans) {
cout << el << "\n";
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |