Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <deque>
- #include <algorithm>
- #include <set>
- using namespace std;
- int getUnusedMin(int min, set <int>& already_used) {
- while (already_used.find(min) != already_used.end()) {
- min++;
- }
- return min;
- }
- int getUnusedMax(int max, set <int>& already_used) {
- while (already_used.find(max) != already_used.end()) {
- max--;
- }
- return max;
- }
- int main() {
- int n;
- cin >> n;
- vector <int> v(n);
- for (auto& elem : v) {
- cin >> elem;
- }
- int min = 1;
- int max = INT_MAX;
- set <int> alredy_used;
- vector<int> result;
- result.push_back(v[0]);
- alredy_used.insert(v[0]);
- for (int i = 1; i < v.size(); ++i) {
- min = getUnusedMin(min, alredy_used);
- max = getUnusedMax(max, alredy_used);
- if (v[i - 1] == v[i]) {
- result.push_back(min);
- result.push_back(max);
- alredy_used.insert(min);
- alredy_used.insert(max);
- continue;
- }
- if (v[i - 1] < v[i]) {
- result.push_back((alredy_used.find(v[i]) != alredy_used.end() ? max : v[i]));
- alredy_used.insert((alredy_used.find(v[i]) != alredy_used.end() ? max : v[i]));
- max = getUnusedMax(max, alredy_used);
- result.push_back(max);
- alredy_used.insert(max);
- continue;
- }
- result.push_back((alredy_used.find(v[i]) != alredy_used.end() ? min : v[i]));
- alredy_used.insert((alredy_used.find(v[i]) != alredy_used.end() ? min : v[i]));
- min = getUnusedMin(min, alredy_used);
- result.push_back(min);
- alredy_used.insert(min);
- }
- for (auto& elem : result) {
- cout << elem << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement